#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
int main() {
	ifstream instream;
	ofstream outstream;
	instream.open("io.txt");
	//outstream.open("io.txt");
	if (instream.fail())
	{
		cout << "failed";
		exit(1);
	}
	if (outstream.fail())
	{
		cout << "out failed";
		exit(1);
	}
	int first, second;
	instream >> first >> second;
	cout << first << second;
	outstream << "the first number is" << first << "\n the second number is" << second;//
	instream.close();
	//outstream.close();
	return 0;
}

原因是这种读写方式是读一个文件,写入另一个文件,如果写同一个文件,就会出错

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐