ifstream/ofstream
Can anyone help me to modift these code to similar code that can save into text files?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
ifstream data;
data.open("CustRecord.txt");//txt files
if(data.is_open())//if file found
{
int size1,read1;
string read2;
char read3;
data>>read1;
size1=read1;
for(int r=0; r<size1;r++){
data>>read1;
input.push_back(read1);z++;}//pushback at last line
for(int r=0; r<size1;r++){
data>>read3;obj.name[100]=read3;
data>>read2;obj.ic=read2;
data>>read2;obj.email=read2;
data>>read2;obj.roomtype=read1;
data>>read1;obj.roomfees=read1;
data>>read1;obj.night=read1;
data>>read2;obj.check_in_date=read2;
obj2.push_back(obj);
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
ofstream data;
data.open("CustRecord.txt",ios::out);
if(data.is_open()){
data<<input.size()<<endl;
for(int r=0; r<input.size();r++){
data<<input[r]<<endl;}
for(int r=0; r<input.size();r++){
data<<"\n";
data<<"Customer Name: "<<obj2[r].name<<endl;
data<<"Customer IC: "<<obj2[r].ic<<endl;
data<<"Customer Email address: "<<obj2[r].email<<endl;
data<<"Customer Room Type Choice: "<<obj2[r].roomtype<<endl;
data<<"Customer Room Fees: "<<obj2[r].roomfees<<endl;
data<<"Number of Night: "<<obj2[r].night<<endl;
data<<"Check in Date: "<<obj2[r].check_in_date<<endl;
}
data.close();
}
|
Topic archived. No new replies allowed.