一般用gets(),就能實現讀帶空格的,但有時候,不知道為啥,用gets會莫名出錯。//千萬不要用gets()!!!
這裡來說說cin.get();(c++的題居然考的這);如;讀取
tom hanks&18&7817&80&80&90&70
#includeusing namespace std;
int main(){
char a[30];
cin.get(a,20,'&');
//這裡我規定最多讀取20個,或者讀到'&'結束。
//這20個裡面最後是個'\n',所以說只能看見19個。
cout這裡的20,是限制讀取的字串的總長度;下面輸入了21個字元(加上回車).
只有字元達到20以上,直接擷取20個,或者遇見『&』,用來擷取。(『&』之前的回車也會被讀入)
C C 輸入帶空格的字串
機試的時候碰到的問題,當時腦子卡克到想不出來怎麼處理,用了一種賊複雜的方法,現在整理下!include include int main 一句gets解決的事情,我居然tm沒想起來。太羞恥了 include include int main include include int main incl...
scanf讀取含空格的字串
scanf 函式接收輸入資料時,遇以下情況結束乙個資料的輸入 遇空格 回車 跳格 鍵。遇寬度結束。遇非法輸入。scanf接收包含空格的字串 include int main 輸入 i love you 輸出 i 原因 scanf遇空格結束讀取。解決 include int main 輸入 i lov...
C 連續輸入帶空格的字串
測試檔案 測試1 include include include using namespace std int main 測試結果 顯然cin s不能夠接受空格的輸入 測試2 include include include using namespace std int main 測試結果 顯然g...