访问增强分词器的元素
Access elements of boost tokenizer
我正在尝试使用 boost 将文件的列分配给 std::map。 我想将每行中的元素 0 分配给索引,将元素 2 分配给值。 有没有办法在没有迭代器的情况下做到这一点?addr_lookup行不起作用。
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
int main()
{
std::ifstream myfile("core_info_lowbits.tab", std::ios_base::in);
std::string line;
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(" ");
std::map<std::string, unsigned int> addr_lookup;
while ( std::getline (myfile,line) )
{
tokenizer tokens(line, sep);
//Line below does not work
addr_lookup[*tokens.begin()] = boost::lexical_cast<unsigned int> (*(tokens.begin()+2));
for (tokenizer::iterator tok_iter=tokens.begin();
tok_iter != tokens.end(); ++tok_iter)
std::cout << *tok_iter << std::endl;
}
}
您正在尝试使用 +
推进迭代器,这是不可能的
用:
tokenizer::iterator it1,it2= tokens.begin();
it1=it2;
++it2; ++it2;
addr_lookup[*it1] = boost::lexical_cast<unsigned int> (*it2);
或者简单地说,
tokenizer::iterator it1,it2= tokens.begin();
it1=it2;
std::advance(it2,2);
addr_lookup[*it1] = boost::lexical_cast<unsigned int> (*it2);
相关文章:
- 将函数分配给C 中的数组元素
- 在标准向量中将元素分配给 Eigen::Vector2d 会引发错误
- SymSpellPlusPlus 中的分词
- 我无法将二维数组的两个元素的差异分配给C++中其他数组的元素?
- 使用 C++ 的字符串到分词符
- SIGABRT(信号6)在使用分治法查找阵列中的多数元素时出错
- Qt等效于提升分词器表达式/构造
- 如何将2D平行向量的单个元素重新分配给1D向量
- 使用 BOOST 分词器显示分隔符,并且不对引号中的字符串进行分词
- 使用 ICU 进行分词
- C++数学分词器/解析器错误
- 访问增强分词器的元素
- 提升分词器以将带引号的字符串视为一个标记
- 当我的分词器识别出令牌时,如何执行其他操作
- 分词器 - 预期聚合对象使用"{...}"进行初始化
- C++ 分词器变量中的错误'std::stringstream mystream'具有初始值设定项但类型不完整
- 错误的分词
- 分词错误-比较不同的单词在c++输入中出现的次数
- OpenCV 3.0分词故障(视觉词袋)
- 如何将数组的元素分配给 x86 程序集中的变量