- 先看代碼:
string word;
while(cin>>word) {
cout<<word<<endl;
}
-
執(zhí)行代碼,輸入"this is to test input string",輸出如下圖:
解釋:
使用cin輸入字符串時,使用空格來分割輸入的字符串
windows下,停止輸入的方法是:回車鍵——Ctrl+Z——回車
string word;
while(cin>>word) {
cout<<word<<endl;
}
執(zhí)行代碼,輸入"this is to test input string",輸出如下圖:
解釋:
使用cin輸入字符串時,使用空格來分割輸入的字符串
windows下,停止輸入的方法是:回車鍵——Ctrl+Z——回車
