CSVから1行ずつ読み取り、カンマ区切りの各値をトークン化します。各トークンは文字列型です。そして私はそれをfloat型のベクトルに入れています。以下の例では、たとえばcsvの値が "0.08"の場合、* beg = "0.08"ですが、ベクトルvでは"0.079999998"です。
ベクトルの精度を小数点以下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()));
}