By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,691 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

iomanip: setwidth was not declared in this scope

P: n/a
After trying to compile the following code, gcc gives me

error: 'setwidth' was not declared in this scope

I'm not sure why it would do this, since iomanip is included. Am I missing
something?

code:

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int checkPoint(int, int);

int main()
{
int n, i, j, icount;

cout << "Number of possible moves for a knight on a chess board\n\n";

for (j = 1; j <= 8; j++)
{
for (i = 1; i <= 8; i++)
{
icount = checkPoint(i, j);

cout << setwidth(5) << icount;
}
cout << endl;
}
}

int checkPoint(int i, int j)
{
int icount, p, k, n, m;

icount = 0;
p = -1;

for (k = -2; k <= 2; k++)
{
if (k != 0)
{
for (n = 1; n <= 2; n++)
{
p = -p;
m = p * (3 - abs(k));

if (1 <= (i + k) && (i + k) <= 8 && 1 <= (j + m) && (j + m)
<= 8) icount++;
}
}
}
return icount;
}

Apr 18 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Forgot some important information. I'm using Code::Blocks on a Kubuntu
Dapper system. gcc 4.0.3

Vaxius wrote:
After trying to compile the following code, gcc gives me

error: 'setwidth' was not declared in this scope

I'm not sure why it would do this, since iomanip is included. Am I
missing something?

code:

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int checkPoint(int, int);

int main()
{
int n, i, j, icount;

cout << "Number of possible moves for a knight on a chess board\n\n";

for (j = 1; j <= 8; j++)
{
for (i = 1; i <= 8; i++)
{
icount = checkPoint(i, j);

cout << setwidth(5) << icount;
}
cout << endl;
}
}

int checkPoint(int i, int j)
{
int icount, p, k, n, m;

icount = 0;
p = -1;

for (k = -2; k <= 2; k++)
{
if (k != 0)
{
for (n = 1; n <= 2; n++)
{
p = -p;
m = p * (3 - abs(k));

if (1 <= (i + k) && (i + k) <= 8 && 1 <= (j + m) && (j +
m)
<= 8) icount++;
}
}
}
return icount;
}


Apr 18 '06 #2

P: n/a
"Vaxius" <no****@nowhere.net> skrev i meddelandet
news:lY******************************@midco.net...
Forgot some important information. I'm using Code::Blocks on a Kubuntu
Dapper system. gcc 4.0.3

Vaxius wrote:
After trying to compile the following code, gcc gives me

error: 'setwidth' was not declared in this scope

I'm not sure why it would do this, since iomanip is included. Am I
missing something?


/... Code cut .../
Hello,

Replace "setwidth" with "setw".

Regards,
Peter Jansson
http://www.jansson.net/
Apr 18 '06 #3

P: n/a
On Tue, 18 Apr 2006 02:02:33 -0500, Vaxius <no****@nowhere.net> wrote:
After trying to compile the following code, gcc gives me

error: 'setwidth' was not declared in this scope

I'm not sure why it would do this, since iomanip is included. Am I missing
something?

<..>

NMaybe you are trying to use std::setw not std::setwidth
Zara
Apr 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.