C++ string整行读取带空格的字符串
getline函数
定义:
istream& getline (istream& is, string& str, char delim);
istream& getline (istream& is, string& str);
示例:
// extract to string
#include <iostream>
#include <string>
int main ()
{
std::string name;
std::cout << "Please, enter your full name: ";
std::getline (std::cin,name);
std::cout << "Hello, " << name << "!\n";
return 0;
}
参考资料:
CS专业在读,热爱编程。
专业之外,喜欢阅读,尤爱哲学、金庸、马尔克斯。
专业之外,喜欢阅读,尤爱哲学、金庸、马尔克斯。