Hello Valuable Programmers, I have a little Problem with Read on a file and Write on another file with modified like; informations on a exel(.xls) sheet but it doesnt matter we should think like any file type like txt ...; For Example our xls or txt file have this informations initially; xxx 16 segment1 xxx 1 segment2 xxx 8 segment3 yyy 70 segment4 zzz 4 segment5 kkk 2 segment6 mmm 1 segment3 mmm 1 segment7 vvv 6 segment3 ppp 1 segment1 qqq 31 segment8 qqq 50 segment2 qqq 62 segment5 i need to do change this informations like this; xxx total:25 segment1 16,segment2 1,segement3 8 yyy total:70 segment4 70 zzz total:4 segment5 4 kkk total:2 segment6 2 mmm total:2 segment3 1,segment7 1 ... is anyone can make its on C++ its a very important for me, Please help me Thank you so much ....
what you might try is creating a structure to hold the fields of each line - maybe Code: typedef struct { std::string cat; // xxx part int cnt; // numeric part std::string des; // segmentN part } mydata; you could create a vector for input and one for output Code: std::vector<std::vector<mydata> > in_data; std::vector<mydata> out_data; get a priming read on the file and store the first line; loop through your file and check each line against an occurance of cat field at the current_index position. if it doesn't exist, make room and update current_index. Code: if(in_data[current_index][0] != left_most_field_of_file_line) { in_data[current_index].push_back(std::vector<mydata>()); ++current_index; } in_data[current_index].push_back(tmp_mydata_variable); Once the file read completes, iterate over in_data and manipulate the fields as required storing it in out_data. That *should* allow you to write the formatted data to an output file or whatever you need to do. HTH
Create structure or class in C++ programming language. Use three data types as two strings and one integer. Start main() in C++ and then, call this created structure with its given name and arrange all variable and values as your require order of information.