1. 程式人生 > >C++ 讀取檔案內容

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