1、所需头文件:#include <fstream> 2、将数据从内存输出至硬盘文件: char srcFile[] = "src.txt"; ofstream fout(srcFile); fout << "this is test data"; fout.flush();//刷新缓冲区 fout.close();//关闭文件 3、将数据从硬盘文件输入内存: ifstream fin("data.txt"); if (!fin) { cout << "file open error!" << endl; exit(1); } int i = 0; int data[1000]; while(fin >> data[i++]) { ; } fin.close();