《C++PrimerPlus 6th Edition》第4章 複合類型 要點記錄
畫個思維導圖概括:
【習題】
#include<iostream>
#include<string>
using namespace std;
int main(){
int x;
cin>>x;
string str;
//getline(cin,str); //1
cin>>str;//2
cout<<str<<endl;
return 0;
}
運行一下就會發現,兩種方法都有一定問題:首先,getline(cin,address)會把輸入數字回車時留下的換行符轉變爲空字符並傳給address,也就是說當你輸入數字按回車後整個程序就結束了,且address打印看不出任何東西;cin>>address是遇見空格才結束,因此不會有上述問題,但若輸入字符串中有空格,那麼它將只會打印字符串中第一個單詞(或稀飯)。