IOMANIP 错误或“setw”未在此范围内声明

iomanip errors or ‘setw’ was not declared in this scope

本文关键字:范围内 声明 错误 setw IOMANIP      更新时间:2023-10-16

在此函数中:

#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;
}

我收到错误

error: ‘setw’ was not declared in this scope
   cout << setw(4) << arr[i];
                 ^

当我尝试包含iomanip时,在编译过程中出现了很多这样的行:

/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11

这对 Ubuntu 来说有什么特别之处吗?

主文件:

#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;
}
您需要

添加#include <iomanip>才能使用std::setw()。如果你在这方面遇到错误,那么其他事情正在发生,要么是 Ubuntu 的 STL 搞砸了,要么是其他东西干扰了编译。