源程序:
#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:~$
你少了个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
using namespace std;
没有 iostream.h这个文件的
只有 iostream 这个文件 ,没有后缀的追问
不可以阿,结果如第一个追问
追答#nclude
你少了一个i 吧?
#include <iostream>追问
不可以,结果如第一个追问