额,我说仔细一点好了。
就是下面这个代码,但是有错,要怎么改才能把O[9]里面的数据存入到chakan.txt文件中?
#include "stdafx.h"
#include"iostream"
#include"fstream"
#include"string"
#include<conio.h>
using namespace std;
class ORDER
{
private:
string PRONAME;
int ID;
float PRICE;
int NUMBER;
public:
ORDER(){};
void chakan();
};
void ORDER::chakan()
{
ORDER O[9];
O[0].setdingdan("flat shoes",1,20,400);
O[1].setdingdan("leather shoes",2,60,200);
O[2].setdingdan("military shoes",3,15,52);
O[3].setdingdan("footware shoes",4,25,600);
O[4].setdingdan("sports shoes",5,90,100);
O[5].setdingdan("travel shoes",6,80,200);
O[6].setdingdan("canvas shoes",7,75,150);
O[7].setdingdan("high heeled ",8,88,340);
ofstream outfile;
outfile.open("g:\\chakan.txt",ios::out);
if(!outfile)
{
cerr<<"文件打开失败!"<<endl;
exit(0);
}
for(int i=0;i<8;i++)
{
outfile<<O[i]<<endl;
}
outfile.close();
}
int main()
{
ORDER j[8];
ifstream infile;
infile.open("g:\\chakan.txt",ios::in);
if(!infile)
{
cerr<<"文件打开失败!"<<endl;
exit(0);
}
for(int i=0;i<8;i++)
{
infile>>j[i];
cout<<j[i]<<endl;
}
infile.close();
return 0;
}