Linux编译C++文件,说没有找到头文件,怎么啊?新手,不太会用

源程序:
#include <iostream.h>
int main (int argc,char**argv)
{
cout<<"Hello,world!"<<endl;
return 0;
}

终端命令:zhaowei@zhaowei-desktop:~$ g++ -c hello.cpp
hello.cpp:1:22: error: iostream.h: No such file or directory
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:4: error: ‘cout’ was not declared in this scope
hello.cpp:4: error: ‘endl’ was not declared in this scope
zhaowei@zhaowei-desktop:~$

终端命令:(查找标准库头文件)
zhaowei@zhaowei-desktop:~$ locate iostream
/usr/include/c++/4.4/iostream
/usr/include/giomm-2.4/giomm/fileiostream.h
/usr/include/giomm-2.4/giomm/iostream.h
/usr/include/giomm-2.4/giomm/private/fileiostream_p.h
/usr/include/giomm-2.4/giomm/private/iostream_p.h
/usr/include/glib-2.0/gio/gfileiostream.h
/usr/include/glib-2.0/gio/giostream.h
/usr/include/gstreamermm-0.10/gstreamermm/giostreamsink.h
/usr/include/gstreamermm-0.10/gstreamermm/giostreamsrc.h
/usr/include/gstreamermm-0.10/gstreamermm/private/giostreamsink_p.h
/usr/include/gstreamermm-0.10/gstreamermm/private/giostreamsrc_p.h
zhaowei@zhaowei-desktop:~$

不用加.h。。。。

你少了个using namespace std;
或者不加using 这句你就直接用std::cout,std::endl

#include <iostream>
using namespace std;
int main (int argc,char**argv)
{
cout<<"Hello,world!"<<endl;
return 0;
}追问

采用你的程序,这个是g++后到结果:
hello.cpp:1:2: error: invalid preprocessing directive #nclude
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:5: error: ‘cout’ was not declared in this scope
hello.cpp:5: error: ‘endl’ was not declared in this scope
hello.cpp: At global scope:
hello.cpp:7: error: expected constructor, destructor, or type conversion before ‘<’ token

追答

hello.cpp:1:2: error: invalid preprocessing directive #nclude

what's this ?

you typed it wrong...

include ,not nclude

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-21
#include <iostream>
using namespace std;

没有 iostream.h这个文件的

只有 iostream 这个文件 ,没有后缀的追问

不可以阿,结果如第一个追问

追答

#nclude
你少了一个i 吧?

第2个回答  2011-06-21
头文件换一换看看
#include <iostream>追问

不可以,结果如第一个追问

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网