V
Vaxius
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;
}
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;
}