我正在从CSV读取,逐行并标记每个逗号分隔值。每个标记都是一个字符串类型。我将它放入float类型的向量中。在下面的例子中,如果例如csv中的值是“0.08”,* beg =“0.08”,但是在矢量v中它是“0.079999998”设置精度当push_back在向量
有没有办法,我可以设置精度矢量到3位小数或其他东西。
例如:
string line;
boost::char_separator<char> sep(",");
typedef boost::tokenizer< boost::char_separator<char> > t_tokenizer;
ifstream myfile (fileName);
if(myfile.is_open())
{
while (myfile.good())
{
getline (myfile,line);
t_tokenizer tok(line, sep);
for (t_tokenizer::iterator beg = tok.begin(); beg != tok.end(); ++beg)
{
string temp = *beg;
this->v.push_back(::atof(temp.c_str()));
}
*“但是在矢量v中是”0.079999998“”* - 你怎么知道? –
在调试时查看矢量。 – Lexicon