1

我有 fe “我是一名护士。” 我如何或使用哪个函数将单词从字母数字 1 到空格或字母数字 11?

那么我应该得到“正在工作”吗

4

3 回答 3

8

要从流中读取单词,请在字符串上使用 operator>>

std::stringstream  stream("I am working as a nurse.");
std::string  word;

stream >> word;  // word now holds 'I'
stream >> word;  // word now holds 'am'
stream >> word;  // word now holds 'working'
// .. etc
于 2012-12-06T23:06:55.507 回答
2

尚不完全清楚您想要什么,但从您的示例看来,您似乎想要从字符 1 开始并在 11 位之后的字符处结束的子字符串(总共 12 个字符)。这意味着你想要string::substr

std::string str("I am working as a nurse");
std::string sub = str.substr(1,12);
于 2012-12-06T23:09:12.633 回答
0
char[] source = "I am working as a nurse."
char[11] dest;
strncpy(dest, &source[1], 10)
于 2012-12-06T23:11:42.753 回答