c++初学者 第一个程序就运行不了 郁闷死 高手来看看

来源:百度知道 编辑:UC知道 时间:2024/05/29 13:42:00
#include<iostream.h>
using namespace std;
void main(void)
{
cout<<"hello\n";
}

跟书上的对照了n遍没有什么不同的 就是运行不了
怎么回事
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
C:\c++\文件\Cpp1.cpp(2) : error C2871: 'std' : does not exist or is not a namespace
执行 cl.exe 时出错.

把#include<iostream.h>改成#include<iostream>
这是一种以前的写法。现在已经不使用了。
—— 觉得这样的书不用也罢。
cout << "hello\n";虽然不错,但更常见的是cout << "Hello" << endl;

#include<iostream.h>
void main()
{
cout<<"hello\n";
}
这样就可以了。
using namespace std; 是包含在iostream模板中的。
此处不需要。

#include<iostream> //把.h去掉试试
using namespace std;
void main(void)
{
cout<<"hello\n";
}

是在vc下编译的吧?
头俩行改为:
#include<iostream>
using namespace sed;

头文件中带了.h就不要使用using 那句了。不过建议不要使用#include<iostream.h>最好使用#include<iostream.h> using namespace std; 前者是老式的C++版本。

把。h去掉因为你用了using namespace std; 如果不用的化可以带上.h