我需要在我的Linux系统上编译代码。这是简单的代码,但我不知道哪里出了问题:
我有这段代码,但无法编译:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string char1, char2, char3, char4, char5, char6;
cout<<"Hello this is your standard True and False quiz"<<endl;
cout<<"Please enter 'T' or 'F'"<<endl;
cout<<"No#1 George Washington invented the toilet?"<<endl;
cin>>char1;
if ( char1 != "T" || "F")
{
cout<<"You entered an incorrect character please reenter True of False"<<endl;
cin>>char1;
}
if ( char1 != "T" || "F")
{
cout<<"You entered an incorrect character please reenter True of False"<<endl;
cin>>char1;
}
if ( char1 == "T" )
{
cout<<"You entered the incorrect answer. The answer is False"<<endl;
}
cout<<"No#2 The Squareroot of 3136 is 56?"<<endl;
cin>>char2;
if ( char2 != "T" || "F")
{
cout<<"You entered an incorrect character please reenter True of False"<<endl;
cin>>char2;
}
if ( char2 != "T" || "F")
{
cout<<"You entered an incorrect character please reenter True of False"<<endl;
cin>>char2;
}
if ( char2 == "F" )
{
cout<<"You entered the incorrect answer. The answer is True"<<endl;
}
cout<<"No#3
system("PAUSE");
return 0;
}
当我试图编译它时:
gcc file.c
I get:
test.c:1: fatal error: iostream: No such file or directory
compilation terminated.
据我所知,我已经拥有了所有需要的库,我做错了什么吗?
system("PAUSE");
! - David Schwartzsystem("PAUSE")
而不是一个执行完全相同操作的 C++ 函数,因为这两种方法都不会在真正的(非学校、非学习)程序中使用--如果有人花时间编写“按任意键”代码,那么这就是他们没有用来解决实际问题的时间。 - cHaosystem("pause")
(以及其他不太可移植/实现定义的东西),并且没有更重要的原则,比如RAII。当我看到system("pause")
时,我立刻想起这个人,我很生气他仍然有工作,许多人从他那里学习了糟糕的编码实践。system("pause")
只是这个家伙的冰山一角。再加上过多的全局变量,void main()
... - dreamlaxsystem("pause")
,我肯定需要喘口气,回想起来,为此激动真是太傻了... :) - dreamlax