这个程序没错啊 ,为什么编译时会有错呢?编译结果如下: c:\program files\microsoft visual studio\vc98
#include<iostream>usingnamespacestd;enumgame_result{WIN,LOST,TIE,CANCEL};intmain(){ga...
#include<iostream>
using namespace std;
enum game_result {WIN,LOST,TIE,CANCEL};
int main()
{
game_result result;
enum game_result omit =CANCEL;
int count;
for(count=WIN;count<=CANCEL;count++)
{
result=(game_result)count;
if(result==omit)
{
cout<<"The game was cancelled\n";
}
else
{
cout<<"The game was played";
if(result==WIN)
cout<<"and we win!";
if(result==LOSE)
cout<<"and we lost!";
cout<<"\n";
}
}
}
是啊,可是编译器编译出的结果是:c:\program files\microsoft visual studio\vc98\include\eh.h(32) : fatal error C1189: #error : "eh.h is only for C++!"
Error executing cl.exe.
My.exe - 1 error(s), 0 warning(s)
是编译器的问题吗? 展开
using namespace std;
enum game_result {WIN,LOST,TIE,CANCEL};
int main()
{
game_result result;
enum game_result omit =CANCEL;
int count;
for(count=WIN;count<=CANCEL;count++)
{
result=(game_result)count;
if(result==omit)
{
cout<<"The game was cancelled\n";
}
else
{
cout<<"The game was played";
if(result==WIN)
cout<<"and we win!";
if(result==LOSE)
cout<<"and we lost!";
cout<<"\n";
}
}
}
是啊,可是编译器编译出的结果是:c:\program files\microsoft visual studio\vc98\include\eh.h(32) : fatal error C1189: #error : "eh.h is only for C++!"
Error executing cl.exe.
My.exe - 1 error(s), 0 warning(s)
是编译器的问题吗? 展开
展开全部
我通过复制你的代码,在Microsoft Visual Studio 2008中进行编译,文件名为“game_result.cpp”。
首先出现了“错误 fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添#include "stdafx.h"?”。
加上“#include "stdafx.h"”后,出现的“错误 error C2065: “LOSE”: 未声明的标识符”, if(result==LOSE)中的LOSE与enum game_result {WIN,LOST,TIE,CANCEL};中的LOST不一致。
修改后的代码如下:
#include "stdafx.h"
#include<iostream>
using namespace std;
enum game_result {WIN,LOST,TIE,CANCEL};
int main()
{
game_result result;
enum game_result omit =CANCEL;
int count;
for(count=WIN;count<=CANCEL;count++)
{
result=(game_result)count;
if(result==omit)
{
cout<<"The game was cancelled\n";
}
else
{
cout<<"The game was played";
if(result==WIN)
cout<<"and we win!";
if(result==LOST)
cout<<"and we lost!";
cout<<"\n";
}
}
}
编译结果为:
The game was playedand we win!
The game was playedand we lost!
The game was played
The game was cancelled
首先出现了“错误 fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添#include "stdafx.h"?”。
加上“#include "stdafx.h"”后,出现的“错误 error C2065: “LOSE”: 未声明的标识符”, if(result==LOSE)中的LOSE与enum game_result {WIN,LOST,TIE,CANCEL};中的LOST不一致。
修改后的代码如下:
#include "stdafx.h"
#include<iostream>
using namespace std;
enum game_result {WIN,LOST,TIE,CANCEL};
int main()
{
game_result result;
enum game_result omit =CANCEL;
int count;
for(count=WIN;count<=CANCEL;count++)
{
result=(game_result)count;
if(result==omit)
{
cout<<"The game was cancelled\n";
}
else
{
cout<<"The game was played";
if(result==WIN)
cout<<"and we win!";
if(result==LOST)
cout<<"and we lost!";
cout<<"\n";
}
}
}
编译结果为:
The game was playedand we win!
The game was playedand we lost!
The game was played
The game was cancelled
展开全部
你想要的是什么效果呢?
是这样的吗?
#include<iostream>
using namespace std;
enum game_result {WIN,LOSE,TIE,CANCEL};
void main()
{
game_result result;
enum game_result omit =CANCEL;
int count;
for(count=WIN;count<=CANCEL;count++)
{
result=(game_result)count;
if(result==omit)
{
cout<<"The game was cancelled\n";
}
else
{
cout<<"The game was played";
if(result==WIN)
cout<<"and we win!";
if(result==LOSE)
cout<<"and we lose!";
cout<<"\n";
}
}
}
是这样的吗?
#include<iostream>
using namespace std;
enum game_result {WIN,LOSE,TIE,CANCEL};
void main()
{
game_result result;
enum game_result omit =CANCEL;
int count;
for(count=WIN;count<=CANCEL;count++)
{
result=(game_result)count;
if(result==omit)
{
cout<<"The game was cancelled\n";
}
else
{
cout<<"The game was played";
if(result==WIN)
cout<<"and we win!";
if(result==LOSE)
cout<<"and we lose!";
cout<<"\n";
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你拿C的编译器去编译C++当然不能编译通过咯
晕……
晕……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把你的文件名称eh.h改为eh.cpp试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
更多回答(2)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询