小编bah*_*rtr的帖子

到达字符串中的特定单词

嗨,我有一个像这样的字符串:

字1 - 选项 - 单词2 - 标签 - WORD3 - 标签 - word4 - 标签 - 的word5 - 标签 - word6

我需要从字符串中提取第三个单词.我想到了逐字逐句阅读并在阅读第二个标签后获得了这个词.但我想它效率低下.你能告诉我一个更具体的方法吗?

c++ string

1
推荐指数
1
解决办法
700
查看次数

atoi和字符串数组

我有一个字符串数组和一个整数数组.我想将字符串数组的元素转换为整数,然后将它们存储在整数数组中.我写了这段代码:

string yuzy[360];
int yuza[360];

for(int x = 0;x<360;x++)
{
    if(yuzy[x].empty() == false)
    {

         yuza[x]=atoi(yuzy[x]);
         cout<<yuza[x]<<endl;
    }
    else
        continue;
}
Run Code Online (Sandbox Code Playgroud)

这段代码给出了这个错误:错误:无法将'std :: string {aka std :: basic_string}'转换为'const char*'以将参数'1'转换为'int atoi(con​​st char*)'

当我在atoi函数中写入字符串的内容(-75dbm)时,它工作正常.但是当我写(yuzy [x])时,我得到了错误.如何使atoi在字符串数组中运行良好?谢谢.

c++ arrays string atoi

0
推荐指数
1
解决办法
8165
查看次数

标签 统计

c++ ×2

string ×2

arrays ×1

atoi ×1