【发布时间】:2014-10-21 23:09:53
【问题描述】:
我有以下代码:
{
line.erase(remove_if(line.begin(), line.end(), ::isspace), line.end()); //removes whitespace
vector<string> strs;
boost::split(strs, line, boost::is_any_of("="));
strs[1].erase(std::remove(strs[1].begin(), strs[1].end(), ';'), strs[1].end()); //remove semicolons
if(strs[0] == "NbProducts") { NbProducts = atoi(strs[1].c_str());
istringstream buffer(strs[1]);
buffer >> NbProducts;
}
但每当我尝试输出 NbProducts 时,我都会得到一个看起来非常随机的数字。顺便说一句,输入来自一个正在读取的文本文件,单行读取:
"NbProducts = 1234;"
没有引号。
我知道现在的代码有点草率。但是谁能立即看到为什么我会用奇怪的整数代替“NbProducts”?
【问题讨论】:
-
您是否尝试解析文本语法?你可能应该be XY-phrasing your question a little。