#include <iostream.h>
int main()
{
std::cout<<"HELLO WORLD!"<<std::endl;
return 0;
}
int main()
{
}
编译没错,执行出错:
d:\visualc++程序设计教程程序\hello word.cpp(4) : error C2653: 'std' : is not a class or namespace name
d:\visualc++程序设计教程程序\hello word.cpp(4) : error C2653: 'std' : is not a class or namespace name
d:\visualc++程序设计教程程序\hello word.cpp(4) : error C2653: 'std' : is not a class or namespace name
改为:
#include <iostream>
int main()
{
std::cout<<"HELLO WORLD!"<<std::endl;
return 0;
}
int main()
{
}
正确:
'std' : is not a class or namespace name,解决
2009年02月19日 星期四 下午 10:07
要用std::名字空间 在包含标准库文件时不要带“.h”
例:#include <iostream> (不要)-#include <iostream.h>)
以下是引用:
“<fstream.h>是标准库出台前的头文件。
<fstream>是标准库的头文件。
using namespace std;声明调用的是标准库的东西。”
“标准库出台后为了不和以前的混淆
将类似于<fstream.h>的头文件
放入到叫std 的namespace里
并叫头文件为<fstream> ”
“如果用了#include<fstream.h>
那么所有的东西都不会放在std名字空间里。”