iomanip errors or ‘setw’ was not declared in this scope
18,523
You need to add #include <iomanip>
in order to use std::setw()
. If you are getting errors on that, then something else is going on, either Ubuntu's STL is messed up, or something else is interfering with the compile.
Related videos on Youtube
Author by
Tami
Updated on June 04, 2022Comments
-
Tami almost 2 years
In this function:
#include <iostream> using namespace std; extern const int M; void outnum(int* &arr) { for (int i=0; i<M; i++) cout << setw(4) << arr[i]; cout << endl; }
I get an error
error: ‘setw’ was not declared in this scope cout << setw(4) << arr[i]; ^
When I try to include iomanip, during the compilation there appear a lot of lines like this:
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
Is it something special for Ubuntu?
main file:
#include <iostream> #include <locale> extern const int M=5; extern const int N=4; int **makemas(int m, int n); void output(int** &array, int m, int n); int *number(int** &array, int n, int m); void outnum(int* &arr); int main() { int **a, **b; int *anum, *bnum; ... cout<<" Number of minus elements in A:"<<endl; outnum(anum); cout<<" Number of minus elements in B:"<<endl; outnum(bnum); return 0; }
-
chris about 9 yearsWhen the error singles out
std::setw
, it's a good idea to find a reference on it. -
πάντα ῥεῖ about 9 yearsMaybe it's a problem with ubuntu, but I actually doubt it. Here it compiles fine.
-