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 >>, 读取位置跑到下一个数字
原文地址:https://www.cnblogs.com/yaos/p/12031928.html