C++调试的时候出错,怎么找出错误

来源:百度知道 编辑:UC知道 时间:2024/05/16 11:33:18
要方法
我用Microsoft Visual Studio 2005
代码如下:
#include <iostream>
#include "if.h"
int as(int one,int two)
{
if(one>=two) return one;
else return two;
}

void main()
{
int a,b,c;
cout <<"请输入你要比较的数字";
cin >> a >> b;
c=as(a,b);
cout << "恭喜"<<sqrt(c)<<endl;

}
出错提示:
------ 已启动生成: 项目: if, 配置: Debug Win32 ------
正在编译...
if.cpp
.\if.cpp(12) : error C2065: 'cout' : undeclared identifier
.\if.cpp(13) : error C2065: 'cin' : undeclared identifier
.\if.cpp(15) : error C2065: 'endl' : undeclared identifier
.\if.cpp(15) : error C3861: 'sqrt': identifier not found
生成日志保存在“file://d:\My Documents\Visual Studio 2005\Projects\if\if\Debug\BuildLog.htm”
if - 4 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0

我来补充一下,网友 利德 的回答当然是正确的,但这不是推荐的最好做法。
using namespace std; 将把名称空间std内的全部名称导入,这会造成应用程序的全局名称空间污染。
推荐的做法是使用using声明,比如你的程序中用到了cin cout endl:
using std::cin;
using std::cout;
using std::endl;

另外,sqrt好像也没有定义。

如果楼主要的是找到问题的方法,那就参考一下网友 jjbb2 的回答。
但是这段代码里都是低级错误,用眼睛就可以找到了~~呵呵。合格的程序员不应该犯这种错误。加油吧~

你用什么编程的啊,用VC++ 2005它会帮你找的

改成
#include <iostream>
#include<cmath>
#include "if.h"
using namespace std;

你需要在#include <iostream>
后面加上
using namespace std;

利德应该
回答正确.
使用了#include <iostream>
但是没有加上命名空间是不正确的