Home  >  Q&A  >  body text

linux - g++编译,总是提示头文件fstream错误

代码很简单,但是总是提示fstream头文件有错误,操作系统是centos7 64位。

#include <fstream>
#include <iostream>
using namespace std;

int main()
{
    cout<<"hello,world"<<endl;
    return 0;
}

编译报如下错误:
[root@mystudy test]# g++ -o test test.cpp
In file included from /usr/include/c++/4.8.2/fstream:41:0,

             from test.cpp:1:

/usr/include/c++/4.8.2/cstdio:120:11: error: '::ets' has not been declared
using ::ets;

天蓬老师天蓬老师2764 days ago686

reply all(3)I'll reply

  • 黄舟

    黄舟2017-04-17 17:10:18

    Because it is wrong. I don't know when it was modified.

    I have told you so many times not to use root privileges arbitrarily, but you don’t listen. If you have to move a rock if you have nothing to do, will you hit yourself in the foot this time?

    The safest suggestion: Reinstall the system.
    (Possibly) less labor-saving suggestion: reinstall packages like g++ (you may need to uninstall and then install)

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 17:10:18

    The same code can be compiled and tested under gcc v4.8.2 without any problem.
    Look at the error reported here, it should be that ets is not declared at line 120 of the cstdio file. ets没有声明。
    看了下cstdio这个文件,这个地方应该是using ::gets;,所以你看看你的cstdioLooking at the cstdio file, this place should be using ::gets;, so check whether your cstdio file is normal? Has it been modified inside?

    reply
    0
  • 黄舟

    黄舟2017-04-17 17:10:18

    Reinstall build-essential. Once the header file is hung, there is no need to write the rest.

    reply
    0
  • Cancelreply