[英]How can I get a word from string
我有“我正在当护士”。 我或哪个函数如何将单词从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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.