justinY
asked on
output file or fout question (online waiting)
Hi, experts,
I have a file like this
row_elem[0] row_elem[1] row_elem[2] row_elem[3]
111 222 12 333
aaa bbb 0 ccc
AAA BBB 11 CCC
I want to write output to one file by the following rules:
1. always write 01 records, for all the row_elem first , then
2. if row_elem[2] != 0, then write 02 records next to 01 records.
example output:
01 222333111 ( write 01 records, always write 01 records)
02 333 ( write 02 records, because row_elem != 0)
01 bbbcccaaa ( write 01 records, no 02 records because row_elem[2] = 0)
01 BBBCCCAAA ( write 01 records, always write 01 records)
02 CCC ( write 02 records, because row_elem != 0)
I know how to write 01 and 02 seperately by using fout << setw(2) << "01"
<<setw(3) << row_elem[1]
<<setw(3) << row_elem[3]
<<setw(3) << row_elem[0]
<<endl;
BUT I DONT KNOW HOW TO MIX 01 and 02 records like example output above.
ONLINE WAITING. THANKS
I have a file like this
row_elem[0] row_elem[1] row_elem[2] row_elem[3]
111 222 12 333
aaa bbb 0 ccc
AAA BBB 11 CCC
I want to write output to one file by the following rules:
1. always write 01 records, for all the row_elem first , then
2. if row_elem[2] != 0, then write 02 records next to 01 records.
example output:
01 222333111 ( write 01 records, always write 01 records)
02 333 ( write 02 records, because row_elem != 0)
01 bbbcccaaa ( write 01 records, no 02 records because row_elem[2] = 0)
01 BBBCCCAAA ( write 01 records, always write 01 records)
02 CCC ( write 02 records, because row_elem != 0)
I know how to write 01 and 02 seperately by using fout << setw(2) << "01"
<<setw(3) << row_elem[1]
<<setw(3) << row_elem[3]
<<setw(3) << row_elem[0]
<<endl;
BUT I DONT KNOW HOW TO MIX 01 and 02 records like example output above.
ONLINE WAITING. THANKS
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER