我怎样才能从字符串中得到一个单词
How can I get a word from string
我有f.e."我是一名护士。我或哪个函数如何使用将单词从字母 1 获取到空格或字母 11?
所以我应该得到"正在工作"
要从流中使用运算符>>在字符串上读取单词
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
目前还不完全清楚您想要什么,但从您的示例中,您似乎想要从字符 1 开始并在字符 11 位之后结束的子字符串(总共 12 个字符)。这意味着您需要string::substr
:
std::string str("I am working as a nurse");
std::string sub = str.substr(1,12);
char[] source = "I am working as a nurse."
char[11] dest;
strncpy(dest, &source[1], 10)
相关文章:
- 使用std::mt19937从字符串中返回一个随机单词
- C++-字符串是否包含一个带有简单循环的单词
- 为什么这个程序返回最后一个单词而不是最长的单词?
- 3-3. 编写一个程序来计算每个不同单词在其输入中出现的次数
- 计算单词中的音节数,但考虑到单词中彼此相邻的任何元音都算作一个音节
- 如何检查流中文件的下一个单词是否为 alpha?
- 给定一个单词数组和一个字符串,如何计算给定字符串中的所有单词
- 计算一个单词在映射中出现的次数 - 使用 transform() - 调用不匹配
- 如何制作一个程序,它使用特定单词加密和解密消息?
- 创建一个函数,返回给定单词在C++中的频率
- 如何将一个单词拆分成字母,并将它们放入一个无序的列表/集合中
- 输入一个字符串并将其除以单词
- 我有一个字符串变量单词= "APA"
- 将字符串中的单个单词替换为另一个单词
- 如何创建一个函数,该函数在文本中查找单词的匹配项,包括跳过
- 如何将行的第一个单词作为一个变量,将行的其余部分作为另一个变量进行归档/存储
- 给定一个字符串,只要您看到单词"ant"替换到字符串中,单词就会"termite"
- 当字符串中只有一个"GOOD"字符串可用时,从没有空格的字符串中提取第一个单词的最佳和有效方法?
- 检查一个文本文件中的单词是否在另一个文本文件 (C++) 中
- 如何插入一个单词并将字母放在2D数组中的不同索引中