一个简单的C++编程,麻烦一下..

来源:百度知道 编辑:UC知道 时间:2024/05/12 14:03:43
提示有一个错误,我不知道是哪.代码如下
#include "stdafx.h"

int main(int argc, char* argv[])
{
int x,y,t;
cout<<"输入两个数字"<<endl;
cin>>x>>y;
if(x<y)
{
t=x;x=y;t=y;
}
cout<<"x="<<x<<"y="<<y<<endl;
cin>>x;
return 0;
}

例2 3.cpp(10) : error C2065: 'cout' : undeclared identifier
e:\myprojects\例2 3\例2 3.cpp(10) : error C2297: '<<' : illegal, right operand has type 'char [13]'
e:\myprojects\例2 3\例2 3.cpp(10) : error C2065: 'endl' : undeclared identifier
e:\myprojects\例2 3\例2 3.cpp(11) : error C2065: 'cin' : undeclared identifier
e:\myprojects\例2 3\例2 3.cpp(11) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
e:\myprojects\例2 3\例2 3.cpp(16) :

#include "stdafx.h" //你这个是用来干什么的?

#include <iostream>
using namespace std;
//以上是我添加的,这是用来输入与输出的,iostream头文件里的。总之,你在每次编写程序的时候,都把这些添上就行了。
//为什么需要这些?因为算法中有一个特点就是 “可以没有输入,但是必须要有输出”。所以,你必须要有一个输出,必须要包含这个头文件。明白了吗?

int main(int argc, char* argv[])
{
int x,y,t;
cout<<"输入两个数字"<<endl;
cin>>x>>y;
if(x<y)
{
t=x;x=y;t=y;
}
cout<<"x="<<x<<"y="<<y<<endl;
cin>>x;
return 0;
}

#include "stdafx.h" 要这个干什么?

少了这个#include<iostream.h>

漏了
using namespace std;