C++ 读取文件内容

#include <iostream>
#include<fstream>
using namespace std;

void main()
{
	char a;
	fstream openfile("D:\\下载\\C++\\test\\test\\1.txt");// 文件位置及名称,记得双斜杠,文件名称是1.txt,其它的是路径
	if (!openfile)
	{
		cout << "open failed!" << endl;
		exit(1);
	}
	do {
		openfile.get(a);
		if (openfile.eof())
			break;
		cout << a; // 存到 a,以每个字符存
	} while (!openfile.eof());
	cout << endl;
	system("pause");
}

转载源地址:https://zhidao.baidu.com/question/89768485.html

猜你喜欢

转载自blog.csdn.net/qq_38233824/article/details/84931288