我一直在努力理解为什么这个示例代码不能在我的 C++ 编译器中运行。我正在使用 Code::Blocks,我的 main.cpp 程序可以工作,但在同一个源中,我有另一个示例程序,名为 if_else.c(因为它自动将“.c”部分命名为自己。)这是示例我放在那里的代码:
#include <iostream>
using namespace std;
int main()
{
int age;
cout<<"Please input your age: ";
cin>> age;
cin.ignore();
if ( age < 100 ) {
cout<<"You are pretty young!\n";
}
else if ( age == 100 ) { // I use else just to show an example
cout<<"You are old\n"; // Just to show you it works...
}
else {
cout<<"You are really old\n"; // Executed if no other statement is
}
cin.get();
}
现在,每次我去构建代码时,我都会得到这个错误:
“ fatal error :iostream:没有那个文件或目录。
现在我是 C++ 编码的新手,因为我一直在使用 LabVIEW。我知道我在编译器设置中的路径在“工具链可执行文件”下可能是错误的,但它似乎没问题。
如果您有任何建议,我会洗耳恭听。
最佳答案
您已将文件保存为 .c
。所以编译器会尝试将其编译为 C 代码。将其重命名为 .cpp
将使编译器将其编译为 C++ 代码。
关于c++ - fatal error : iostream: No such file or directory - Can you help fix this?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30294488/