C++——getline函數的使用

#include
#include <string>
using namespace std;


int main()
{
string str;
cout<<"Please enter your name.\n";
getline(cin,str);//輸入整行,放入str,包括空格;【enter】結束
cout<<"Hello,"<<str<<"!\n";//輸出
std::cin.ignore(std::cin.rdbuf()->in_avail()+1);

return 0;

}

函數getline()輸入一個完整的行。

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章