C++ fstream 用法
#include <fstream>
#include <iostream>
main()
{
int a,b,c,d;
std::ifstream infile ("test.txt", std::ifstream::in);
while (!infile.eof())
{
infile >> a;
infile >> b;
infile >> c;
infile >> d;
}
std::cout << a << std::endl;
}
text.txt
1 2 6 5
- 数字以空格(数量不限)分隔即可
- 每运行一次
infile >>
, 读取位置跑到下一个数字