using namespace std 这句话有什么功能
我是一个菜鸟,最近在学习c++的过程中遇到这样的问题
有一个题目:设某次体育比赛的结果有四种可能:胜(win),负(lose),平局(tie),比赛取消(cancle),编写程序顺序输出这四种情况。
源程序为:
#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 won!";
if(result==LOST)
cout<<"and we lost.";
cout<<"\n";
}
}
return 0;
}
如果没有红色的那句程序,编译就不成功,那这句话的作用是什么呢?
而且添加上那句,编译后会出现:
The game was played
press any key to continue
并没有出现预想的运行结果:
The game was played and we won;
The game was played and we lost;
The game was played
The game was cancelled
到底是怎么回事啊?拜请高手指点!