已解决问题

C++程序的一个问题

10
[ 标签:c++,c++ 程序,程序 ]
#include <iostream>

int Add (int first, int second)
{
std::cout << "In Add (), received " << first << " and " << second << "\n";
return (first + second);
}

int main()
{
using std::cout;
using std::endl;

cout << "I'm in main()!\n";
int a, b, c;
cout << "Enter two numbers: ";
cin >> a;
cin >> b;
cout << "\nCalling Add()\n";
c=Add(a,b);
cout << "\nBack in main() .\n";
cout << "c was set to " << c;
cout << "\nExiting\n\n";
return 0;
}

编译器是VS C++ 6.0

提示错误:F:\C++\MSDev98\MyProjects\jw\123.cpp(17) : error C2065: 'cin' : undeclared identifier
F:\C++\MSDev98\MyProjects\jw\123.cpp(17) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
F:\C++\MSDev98\MyProjects\jw\123.cpp(18) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
Error executing cl.exe.

不知道该如何解决
问题补充  2009-01-21 19:13
正常运行过,是程序的问题,不知道错在哪.希望强人解决一下
匿名 回答:1 人气:17 解决时间:2009-01-21 19:52
  
满意答案
#include <iostream>
using namespace std;
int Add (int first, int second)
{
std::cout << "In Add (), received " << first << " and " << second << "\n";
return (first + second);
}

int main()
{
using std::cout;
using std::endl;

cout << "I'm in main()!\n";
int a, b, c;
cout << "Enter two numbers: ";
cin >> a;
cin >> b;
cout << "\nCalling Add()\n";
c=Add(a,b);
cout << "\nBack in main() .\n";
cout << "c was set to " << c;
cout << "\nExiting\n\n";
return 0;
}
加上using namespace std;就行了。
回答采纳率:100.0% 2009-01-21 19:44
评价答案
  • 是否解决问题(参与评价0次)
  • 0
  • 0
  • 0
  • 是否原创答案(参与评价0次)
  • 0
  • 0
提问人的感言:
感谢.能留个QQ么,以后有问题请教你

相关内容