我正在尝试使用 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;
}
}