2 Replies - 515 Views - Last Post: 22 October 2009 - 11:22 AM Rate Topic: -----

#1 crochunter  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 74
  • Joined: 29-May 09

Multimap output files problems

Post icon  Posted 22 October 2009 - 03:43 AM

Hi. :pirate:
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 :crazy:

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 :P

Is This A Good Question/Topic? 0
  • +

Replies To: Multimap output files problems

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: Multimap output files problems

Posted 22 October 2009 - 09:04 AM

Do you need to open your file in append mode perhaps?
Was This Post Helpful? 0
  • +
  • -

#3 crochunter  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 74
  • Joined: 29-May 09

Re: Multimap output files problems

Posted 22 October 2009 - 11:22 AM

View PostJackOfAllTrades, on 22 Oct, 2009 - 08:04 AM, said:

Do you need to open your file in append mode perhaps?


Well do you think its the only thing that is required ? :rolleyes:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1