Hi. :-/
I am trying to create multiple output files while reading a single input file. The multiple files will be created based on the value in the first field.
My set1 contains 1,2,3,2,1,3. That is Field1 values.
My multimap contains the other fields (field2 and field3).
Now what I am trying to do is to use ofstream to output multiple output files dynamically. Its just creating 1 file and duplicating records :sad:
Here is my input file:-
1 AAAAAA BBBBBB
2 DDDDDD EEEEEE
3 GGGGGG HHHHHH
2 NNNNNN LLLLLL
1 UUUUUU KKKKKK
3 SSSSSS BBBBBB
This is how I expect my output to be:-
file1.txt:
1 AAAAAA BBBBBB
1 UUUUUU KKKKKK
file2.txt:
2 NNNNNN LLLLLL
2 DDDDDD EEEEEE
file3.txt:
3 GGGGGG HHHHHH
3 SSSSSS BBBBBB
Here is my code so far:-
set1.insert(field1);
for(itv=set1.begin(); itv !=set1.end(); itv++)
{
if(chr.compare(*itv)==0){
string filenamei = "myfile";
multimap<string,string> mmi;
ofstream out;
mmi.insert (pair<string,string>(band,start));
out.open(filenamei.c_str());
for (it= mmi.begin(); it != mmi.end(); it++){
cout << (*it).first << "\t" << (*it).second << endl;
}
}//end of if loop
}
Thanks :X