输入string类型的值
废话不说,直接上代码…
#include<iostream>
using namespace std;
int main()
{
//输入string类型的值
char cInput[20];
//读取一个单词
cin >> cInput;
cout << cInput << endl;
//读取一行 \n 不要了
cin.getline(cInput, 20);
cin.getline(cInput, 20, ':'); //指定结束符
cout << cInput << endl;
//读取一行 \n加入到队列中
cin.get(cInput, 20);
cout << cInput << endl;
string sInput;
//读取一个单词
cin >> sInput;
//读取一行
getline(cin, sInput);
getline(cin, sInput, ':'); //指定结束符
cout << sInput << endl;
return 0;
}