头文件加上
#include <fstream>
下面是例子:
char buffer[12],buffer2[12];
// 读文件
ifstream trainingfile ("trainingData.txt");
if(!trainingfile){
cout << "Unable to open trainingfile";
exit(1); // terminate with error
}
while (!trainingfile.eof())
{
trainingfile.getline(buffer,12);
sscanf(buffer,"%c %c %c %c %c %c",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5])
}
trainingfile.close();
//写文件
ofstream outputfile("output.txt");
if(!outputfile){
cout << "Unable to open otfile";
exit(1); // terminate with error
}
// 利用outputfile一直向里面添加东西即可
outputfile<<b[0]<<' '<<b[1]<<' '<<b[2]<<' '<<endl;
//写完后
outputfile.close();