标题c++ 中的getLine 函数
类似于 Java 中 string nextLine()函数,获取当前输入的一行。
// This program illustrates using the getline function
//to read character data into a string object.
#include <iostream>
**#include <string> // Header file needed to use string objects**
// getline()属于string流
using namespace std;
int main()
{
string name;
string city;
cout << "Please enter your name: ";
getline(cin, name);
cout << "Enter the city you live in: ";
getline(cin, city);
cout << "Hello, " << name << endl;
cout << "You live in " << city << endl;
return 0;
}
可以把空格,或回车 ,同时一起获取 。