我从这里下载了 Code::Blocks:http://www.codeblocks.org/downloads/26 http://www.codeblocks.org/downloads/26
我正在学习c编程。当我运行以下程序时,出现错误:
iostream: No such file or directory
error: syntax error before "namespace"
warning: type defaults to `int' in declaration of `std'
warning: data definition has no type or storage class
In function `main':
error: `cout' undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
error: `cin' undeclared (first use in this function)
我正在运行以下程序:
#include <iostream>
using namespace std;
int main()
{
int x;
x = 0;
do {
// "Hello, world!" is printed at least one time
// even though the condition is false
cout<<"Hello, world!\n";
} while ( x != 0 );
cin.get();
}
我尝试了 Dev-C++,也遇到了同样的错误。
如何解决这个问题?
这是在“program.c”或“program.cpp”之类的文件中吗?如果它是 .c 文件,那么您的编译器可能会将其解释为 C,而不是 C++。这很容易导致这样的错误。可以“强制”编译器将此类扩展名视为另一个,但默认情况下,.c 文件适用于 C,而 .cpp 文件则编译为 C++。
要么是这个,要么是标准库的默认“包含”目录设置不正确,但我不知道如何解决这个问题,因为这取决于编译器/环境。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)