473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Mulltimap multiple file output

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

Here is my input file:-
Expand|Select|Wrap|Line Numbers
  1. 1    AAAAAA    BBBBBB    
  2. 2    DDDDDD    EEEEEE
  3. 3    GGGGGG    HHHHHH
  4. 2    NNNNNN    LLLLLL
  5. 1    UUUUUU    KKKKKK  
  6. 3    SSSSSS  BBBBBB
This is how I expect my output to be:-
Expand|Select|Wrap|Line Numbers
  1. file1.txt:
  2. 1    AAAAAA    BBBBBB
  3. 1    UUUUUU    KKKKKK
  4.  
  5. file2.txt:
  6. 2    NNNNNN    LLLLLL
  7. 2    DDDDDD    EEEEEE
  8.  
  9. file3.txt:
  10. 3    GGGGGG    HHHHHH
  11. 3    SSSSSS  BBBBBB
Here is my code so far:-
Expand|Select|Wrap|Line Numbers
  1.           set1.insert(field1);
  2.      for(itv=set1.begin(); itv !=set1.end(); itv++)
  3.  
  4.      {
  5.        if(chr.compare(*itv)==0){
  6.           string filenamei = "myfile";
  7.           multimap<string,string> mmi;
  8.           ofstream out;
  9.           mmi.insert (pair<string,string>(band,start));
  10.           out.open(filenamei.c_str());
  11.        for (it= mmi.begin(); it != mmi.end(); it++){
  12.  
  13.               cout << (*it).first << "\t" << (*it).second << endl;
  14.        }
  15.  
  16.        }//end of if loop
  17.      }
Thanks
Oct 22 '09 #1
3 3803
mac11
256 100+
Your code is only opening one output file.

If you want to write to multiple files you need to have multiple output streams (one for each file), and then write the data to each one.

I suppose you can do it with one output stream just open file1, write data, close stream, open file2, write data, close, etc...
Oct 22 '09 #2
Ya thats true but as per my problem there could be any number of output files that could be generated based on my first field values. So I was thinking a way by what I can do it dynamically ?
Like using a for loop and creating output files

Like file[i].txt

Thanks
Oct 22 '09 #3
Banfa
9,065 Expert Mod 8TB
Your code already contains a for loop editing the file, all you have to do is use a different file name each time round the loop.
Oct 23 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Georg Teichtmeister | last post by:
Hello! We are developing a math - library for realtime applications and want to use some given mathlibraries as base(ipp, MTL, .. ). Our library is a wrapper for those and you should be able to...
4
by: Tristan Miller | last post by:
Greetings. I would like to produce a static multilingual website in XHTML. Is it possible to specify each web page in its own XML file, but have all of the translations encapsulated in that one...
5
by: Jeff | last post by:
We are using .Net and the wsdl Utility to generate proxies to consume web services built using the BEA toolset. The data architects on the BEA side create XML schemas with various entities in...
13
by: a.zeevi | last post by:
free() multiple allocation error in C ==================================== Hi! I have written a program in C on PC with Windows 2000 in a Visual C environment. I have an error in freeing...
4
by: yancheng.cheok | last post by:
Recently, I try to replace #define with const in header file. However, there are concerns on, multiple const object will be created, if the header file is included in multiple cpp files. For...
15
by: leorulez | last post by:
Is there any way to read multiple files (more than 1000 files) and then write into one single output file using C? Right now in my program, I have a loop which asks for the filename and writes into...
3
by: jparulan | last post by:
Hi All, I'm using SOAP3.0. I was able to successfully call a WSDL file and get a value properly. But when the WSDL changed to have a MULTIPLE <element name> it was failing. This code works...
3
by: Tim | last post by:
Hi Folks, I'm used to a UNLOAD command that allows me to dump to a named flat file the results of any SELECT statement. Hence one can build a single SQL file which contains multiple SQL...
3
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.