C++中文件的输入/输出操做

1:ifstream类,从istream 类派生而来,该类的对象用来支持文件的输入;
2:ofstream类,从ostream派生而来,该类的对象用来支持文件的输出;
3:fstream类 ,由iostream派生而来,能够支持文件的输入输出;
文件的写入ios

int main()
{
	ofstream ofile;
	ofile.open("Test1.txt");
	if (!ofile)
	{
		cout << "Can not open file test.txt\n";
	}
	else
	{
		ofile << 10 << " " << 123.45 << "This is a file"<<endl;
	}
	ofile.close();
	system("pause");
	return 0;
}

读取数据:web

int i;
	float f;
	char str1[80];
	
	ifstream in("Test1.txt");
	if (!in.is_open())
	{
		cout << "Can not open this file" << endl;
	}
	else
	{
		in >> i >> f>>str1;
		cout << i << f<<endl;
		cout << str1 << endl;

	}
	system("pause");
	return 0;