C++ getline函数用法详解

link

#include <iostream>
#include <string> // Header file needed to use string objects
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;
}
Please enter your name: 海龙
Enter the city you live in: 上海
Hello, 海龙
You live in 上海

posted @ 2022-08-19 22:45  luoganttcc  阅读(25)  评论(0)    收藏  举报