C++ c++;将2个或多个字符串分组为一个输入
可能重复:C++ c++;将2个或多个字符串分组为一个输入,c++,string,variables,C++,String,Variables,可能重复: 我使用cin有困难。我的代码: cout << "Enter Main Keyword: "; cin >> mainKeyword; cout << "==========" << endl; cout << "Enter Secondary Keyword: "; cin >> secondaryKeyword; cout>main关键字; coutcin的默认分隔符是
我使用cin有困难。我的代码:
cout << "Enter Main Keyword: ";
cin >> mainKeyword;
cout << "==========" << endl;
cout << "Enter Secondary Keyword: ";
cin >> secondaryKeyword;
cout>main关键字;
coutcin的默认分隔符是空白,要更改它,请参见以下问题:
或者使用getline
自己执行任何拆分操作。如果要读取整行输入,请使用getline
:
getline(cin, mainKeyword);