亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

簡單的一個問題,求找錯

簡單的一個問題,求找錯

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 關注
  • 2136 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號