cin.getline在输入char时:
using namespace std; const int ArSize = 20; char name[ArSize]; char dessert[ArSize]; cout << "Enter your name:\n"; cin.getline(name, ArSize); // reads through newline cout << "Enter your favorite dessert:\n"; cin.getline(dessert, ArSize);
getline在输入string时:
#include<iostream> #include<string> using namespace std; int main() { string name; string dessert; cout<<"Enter your name:\n"; getline(cin,name); cout<<"Enter your favorite dessert:\n"; getline(cin,dessert);
c++中字符输入函数cin.getline在输入char与string时的不同
原文:https://www.cnblogs.com/joelwang/p/10277302.html