| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1107 人关注过本帖
标题:函数定义题目的问题
只看楼主 加入收藏
洪夜馨
Rank: 1
等 级:新手上路
帖 子:85
专家分:5
注 册:2009-6-12
结帖率:91.43%
收藏
已结贴  问题点数:40 回复次数:7 
函数定义题目的问题
我弄的是:
#include "iostream.h"
int max(int a,int b);
int main()
{
    do
    {
    int h,f,t;
    char q;
    cout<<"请输入你想要比对的整数"<<endl;
    cin>>h>>f;
    cout<<"你输入的整数为"<<h<<"和"<<f<<"吗?"<<endl;
    cout<<"是的话请按Y,反之请按N"<<endl;
    cin<<q;
    if(q!='n'&&'N'&&'y'&&'Y')
    {
        cout<<"输入错误"<<endl;
    }
    }while(q!='y'&&'Y')
        t=max(h,f);
    cout<<"这2个整数中最大的数为"<<t<<endl;
    return 0;
}
int max(int a,int b)
{
    if(a>=b) return a;
    return b;
}
而下面编译的时候显示:
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
F:\教育教学\练习\1.cpp(13) : error C2676: binary '<<' : 'class istream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator
F:\教育教学\练习\1.cpp(18) : error C2065: 'q' : undeclared identifier
F:\教育教学\练习\1.cpp(19) : error C2146: syntax error : missing ';' before identifier 't'
F:\教育教学\练习\1.cpp(19) : error C2065: 't' : undeclared identifier
F:\教育教学\练习\1.cpp(19) : error C2065: 'h' : undeclared identifier
F:\教育教学\练习\1.cpp(19) : error C2065: 'f' : undeclared identifier
执行 cl.exe 时出错.

1.obj - 1 error(s), 0 warning(s)
谁能告诉我哪里错了?

另外再问一下,谁能教教我下面显示的东西怎么看?如果会看了我就能自己解决了.
搜索更多相关主题的帖子: 函数 定义 
2009-07-16 08:49
wuyun8536
Rank: 2
等 级:论坛游民
帖 子:21
专家分:77
注 册:2009-6-7
收藏
得分:40 
#include <iostream>
using namespace std;
int max(int a,int b);
int main()
{
    int h,f,t;
    char q;
    do
    {
    cout<<"请输入你想要比对的整数"<<endl;
    cin>>h>>f;
    cout<<"你输入的整数为"<<h<<"和"<<f<<"吗?"<<endl;
    cout<<"是的话请按Y,反之请按N"<<endl;
    cin>>q;
   if(q!='n'&&q!='N'&&q!='y'&&q!='Y')
    {
        cout<<"输入错误"<<endl;
    }
    }
    while(q!='y'&&q!='Y');
        
        t=max(h,f);
        cout<<"这2个整数中最大的数为"<<t<<endl;
        return 0;
}
int max(int a,int b)
{
    if(a>=b) return a;
    return b;
}
2009-07-16 15:06
洪夜馨
Rank: 1
等 级:新手上路
帖 子:85
专家分:5
注 册:2009-6-12
收藏
得分:0 
using namespace std;
请问一下,是什么意思?
2009-07-16 15:55
洪夜馨
Rank: 1
等 级:新手上路
帖 子:85
专家分:5
注 册:2009-6-12
收藏
得分:0 
哦,我已经发新帖了。谢谢你,wuyun8536。我还是结帖吧。
2009-07-16 16:16
jackie1918
Rank: 2
等 级:论坛游民
帖 子:15
专家分:72
注 册:2009-7-14
收藏
得分:0 
using namespace std;
是使用命名空间~~~算是现在的标准写法~~但友元函数和命名空间不要一起用~~
2009-07-17 17:05
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:0 
以下是引用洪夜馨在2009-7-16 08:49的发言:
Compiling...
1.cpp
F:\教育教学\练习\1.cpp(13) : error C2676: binary '<<' : 'class istream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator
F:\教育教学\练习\1.cpp(18) : error C2065: 'q' : undeclared identifier
F:\教育教学\练习\1.cpp(19) : error C2146: syntax error : missing ';' before identifier 't'
F:\教育教学\练习\1.cpp(19) : error C2065: 't' : undeclared identifier
F:\教育教学\练习\1.cpp(19) : error C2065: 'h' : undeclared identifier
F:\教育教学\练习\1.cpp(19) : error C2065: 'f' : undeclared identifier
执行 cl.exe 时出错.

1.obj - 1 error(s), 0 warning(s)

像这些错误提示确实应该练练自己看,不然老因为一些小语法错误上来问是很耽误时间的~

binary '<<' : 'class istream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator
意义其实就是说既找不着合适的重载版,而且也无法通过自动类型转换匹配到预定义的版本上。
像你这个错的就很明显,cin是一个istream的对象,当然没有重载<<这个运算符了~

'q' : undeclared identifier
这是说,q是个没声明的标识符

syntax error : missing ';' before identifier 't'
这是,语法错误:在标识符t前缺少‘;’

其实大部分错误提示还是挺明显的,一般就算看不懂,它指出了有错的行。去仔细查一查自己也应该能查出错误。这是练基本功的好方法,要加油呀~
2009-07-18 12:22
shaozihaozi
Rank: 1
等 级:新手上路
帖 子:11
专家分:2
注 册:2009-5-5
收藏
得分:0 
这样可以
#include "iostream.h"
int max(int ,int );
void main()
{
   
    int a,b,t;
    char q;
    cout<<"请输入你想要比对的整数"<<endl;
    cin>>a>>b;
    cout<<"你输入的整数为"<<a<<"和"<<b<<"吗?"<<endl;
    cout<<"是的话请按Y,反之请按N"<<endl;
    cin>>q;
    if(q=='y'&&'Y')
        
        {
        t=max(a,b);
        cout<<"这2个整数中最大的数为"<<t<<endl;
        }

    else

    {
        cout<<"输入错误"<<endl;
    }
    
    
}
int max(int a,int b)
{
    if(a>=b)
        return a;
    else
        return b;
}
2009-07-20 15:06
iamchris1992
Rank: 2
来 自:北京
等 级:论坛游民
帖 子:6
专家分:20
注 册:2011-7-5
收藏
得分:0 
看到这个帖子有个新问题:楼主的编译结果最后显示:
执行 cl.exe 时出错.

1.obj - 1 error(s), 0 warning(s)
我也遇到了这种问题,编译器的计数器显示的永远是这个值,问一下这算是个Bug么?是否有办法解决呢?
2011-07-05 10:11
快速回复:函数定义题目的问题
数据加载中...
 
   



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

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