24小时热门版块排行榜    

查看: 498  |  回复: 2

冰雨hust

铁虫 (小有名气)

[求助] 输入输出问题

#include
using namespace std;
template
class compare
{public:
compare(numtype a ,numtype b)
{x=a;y=b;}
numtype max();
numtype min( );
private:
        numtype x;numtype y;
};
template
numtype compare ::max()
{return (x>y)?x:y;}

template
numtype compare ::min()
{return (x


int main()
{ int a;int b;
        compare cmpl(a,b);
        cout<<"please enter two numbers:";
                cin>>a>>b;
cout<<"the max number of the two number is:"< cout<<"the min number of the two number is:"<
return 0;
}
为什么这个程序在编译都通过了,在输入值a,b后(cout<<"the max number of the two number is:"< cout<<"the min number of the two number is:"<
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

libralibra

至尊木虫 (著名写手)

骠骑将军

【答案】应助回帖

感谢参与,应助指数 +1
把compare cmpl(a,b);放在cin>>a>>b之后试试.
在你从终端获得a,b之前,a,b是没有被初始化的任意值
matlab/VB/python/c++/Java写程序请发QQ邮件:790404545@qq.com
2楼2013-03-01 20:46:33
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

haixiawu

金虫 (文坛精英)

【答案】应助回帖

感谢参与,应助指数 +1
逻辑上有错误,compare中的a b不是你输入的a, b
另外,cin >> a >> b; 改成 cin >> a; cin >> b;
3楼2013-03-02 15:21:28
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 冰雨hust 的主题更新
信息提示
请填处理意见