相关疑难解决方法(0)

在两个迭代器之间获取`std :: string`的子字符串

我有一个程序,预计会将一些选项作为输入,以指定形式(p1,p2,p3,...)中的概率.所以命令行的用法实际上是:

./myprog -dist (0.20, 0.40, 0.40)
Run Code Online (Sandbox Code Playgroud)

我想在C++中解析这样的列表,我目前正在尝试使用std :: string类型的迭代器和Boost提供的split函数.

// Assume stuff up here is OK
std::vector<string> dist_strs; // Will hold the stuff that is split by boost.
std::string tmp1(argv[k+1]);   // Assign the parentheses enclosed list into this std::string.

// Do some error checking here to make sure tmp1 is valid.

boost::split(dist_strs,  <what to put here?>   , boost::is_any_of(", "));
Run Code Online (Sandbox Code Playgroud)

注意上面的<what to put here?>部分.因为我需要忽略开头和结尾的括号,我想做类似的事情

tmp1.substr( ++tmp1.begin(), --tmp1.end() )
Run Code Online (Sandbox Code Playgroud)

但它看起来不像substr这样,我无法在文档中找到有效的功能.

我有一个想法是做迭代器算法,如果这是允许的,并用于substr调用

tmp1.substr( ++tmp1.begin(), (--tmp1.end()) - (++tmp1.begin()) …
Run Code Online (Sandbox Code Playgroud)

c++ string parsing

26
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×1

parsing ×1

string ×1