【发布时间】:2018-07-18 15:51:45
【问题描述】:
我需要对字符串进行第二次拆分,在“二”以下的情况下。
我尝试运行此代码:
#include <boost/algorithm/string.hpp>
#include <iostream>
#include <list>
#include <string>
int main()
{
std::string s = "one,two,three,four";
std::list<std::string> results;
boost::split(results, s, boost::is_any_of(","));
std::cout << results[1] << "";
}
我收到此错误:
error: no match for 'operator[]'
我该如何解决?
【问题讨论】:
-
有什么问题?
-
我知道如何拆分,但我不知道在这种情况下如何让第 n 部分得到“两个”
-
cout行不行吗?它打印什么?顺便说一句,比起std::list,更喜欢std::vector。std::list是一个链接列表,它通常比std::vector慢,在这里没有任何好处。 -
这部分不起作用 cout
-
我很困惑,我正在寻找一些例子,但我没有找到