c++字符串操作
请问c++怎么在字符串里搜索第一个空格以前的字符???
.......
char a,b;
......
cin>>a>>b;
...就可以了
程序代码:#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
string str;
getline(cin, str);
auto end {str.cend()};
auto it {find(str.cbegin(), end, ' ')};
if(it != end) {
++it;
}
/* 打印之后的字符, 可以换成其它操作 */
while(it != end) {
cout << *it++;
}
cout << endl;
}