为了账号安全,请及时绑定邮箱和手机立即绑定

简单的一个问题,求找错

简单的一个问题,求找错

C++
有志青年P 2015-09-16 16:12:53
#include<iostream>using namespace std;void main(){int x; if(cin>>x>>1) cout<<"szutic"; else cout<<"你好,深圳大学";}
查看完整描述

4 回答

已采纳
?
onemoo

TA贡献883条经验 获得超454个赞

char x = '\0';
cin >> x;
if (x == '1')
    cout << "szutic" << endl;
else
    cout << "你好" << endl;


查看完整回答
反对 回复 2015-09-17
  • 有志青年P
    有志青年P
    #include<iostream> using namespace std; void main() int x; { cin>>x; if(x==1) cout<<a; else cout<<b; } 为什么这样还错
  • onemoo
    onemoo
    a 和 b 是什么? 这应该是两个变量,可你之前并没有声明它们,编译器会报错的。 要想输出a和b这两个字符,应该用引号括起来:'a' 'b'。 x应该定义在函数体之内。很早期的C可以把变量写在大括号前,但是现在这样写是编译不过的。 还有,函数不需要参数时应声明为 int main(void) 不要把参数列表留空。
  • 有志青年P
    有志青年P
    #include<iostream> using namespace std; int main(void) { int x; cin>>x; if(x==1) cout<<"szutic"<<endl; else cout<<"hello"<<endl; }回复 onemoo:这样也不行
点击展开后面3
?
有志青年P

TA贡献1条经验 获得超0个赞

我的vc++6.0只会报错误的数量不知道在哪错了

这个是慕课的报错


error: iostream: No such file or directory
error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'
In function 'main':
error: 'cin' undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
error: 'cout' undeclared (first use in this function)
error: 'endl' undeclared (first use in this function)
warning: no newline at end of file

查看完整回答
反对 回复 2015-09-19
  • 有志青年P
    有志青年P
    多谢这几天的帮忙,问题已经解决,感谢你的指点,会改进的
?
onemoo

TA贡献883条经验 获得超454个赞

首先,main函数应该声明为 int main()  ,不存在返回类型为void的声明。

if语句括号中最后那个1是字面常量,不能被写入值

查看完整回答
反对 回复 2015-09-16
  • 有志青年P
    有志青年P
    那应该怎么打,我的任务是在输入1时输出szutic,否则输出你好。
?
辛运之旅

TA贡献3条经验 获得超0个赞

既然main函数是无返回值 ,那么return 0;就是多余的了。而且cin>>x>>1 这句看不懂


查看完整回答
反对 回复 2015-09-16
  • 4 回答
  • 0 关注
  • 1925 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信