| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 428 人关注过本帖
标题:用vc2005编c++ 有错误
只看楼主 加入收藏
cychengc
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-3-24
收藏
 问题点数:0 回复次数:2 
用vc2005编c++ 有错误
#include<iostream.h>
#include "stdafx.h"
///////////////////////////最大公约数
int yue(int a, int b)
{
    int c;
    while((c=a%b)!=0)
        return(c);
}
////////////////////////////最小公倍数
int bei(int a, int b)
{
    int m, n;
    m=(a,b);
    n=a*b/m;
    return n;
}
///////////////////////////主函数
void main()
{
    int x,y,c,d;
    cout<<"输入两个数:";
        cin>>x>>y;
        c=yue(x,y);
        d=bei(x,y);
        cout<<"此两数的最大公约数为:"<<c<<endl<<"最小公倍数为:"<<d<<'\n'<<"_____________";
}

其中stdafx.h头文件中没东西。
错误有三处
1>d:\c++\project\hello\hello\hello.cpp(22) : error C2065: 'cout' : undeclared identifier
1>d:\c++\project\hello\hello\hello.cpp(23) : error C2065: 'cin' : undeclared identifier
1>d:\c++\project\hello\hello\hello.cpp(26) : error C2065: 'endl' : undeclared identifier
请高手指点。。。是在vc2005中运行的。。 请高手指点详细点。。。
搜索更多相关主题的帖子: void 函数 最小公倍数 include return 
2010-04-13 23:14
wlsj
Rank: 2
等 级:论坛游民
帖 子:49
专家分:28
注 册:2009-5-18
收藏
得分:0 
不会用VC2005,支持一个
2010-04-15 19:20
debroa723
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:23
帖 子:862
专家分:1954
注 册:2008-10-12
收藏
得分:0 
#include<iostream.h>后加上
using spacename std;
或者在
cout\cin\endl 前面加上std::
std::cout
std::cin
std::endl
总之是要说明命名空间。一般的,最好使用第二种方式,因为有些库也会定义cout等,这样容易造成符号的二义性,不明确,直接在cout前加命名空间,明确一些。
2010-04-15 20:41
快速回复:用vc2005编c++ 有错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011597 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved