Max*_*rai 1 c++ parsing stream
我之前做过......但我忘记了.我有一个包含一些数据的文件:
0.5 0.6 0.7 1.2 1.5
如何在c ++中阅读?我用流做了...类似于:
float var = 0;
stream >> var;
Run Code Online (Sandbox Code Playgroud)
以下代码段应该为您提供线索.别忘了包括<fstream>.
std::ifstream fin("filename.txt");
float value;
while (fin >> value)
{
// Do whatever you want with the value
}
Run Code Online (Sandbox Code Playgroud)
不要尝试测试fin.eof()它不会告诉你是否要碰到文件的末尾.