Variable output Filename

Hi, i have no idea how C++ works and i never used it before.
This is the problem:
I have multiple files which i need to split (for example input1 and input 2).
After splitting the input1 file, the output is placed in a map with the names
Output00001.xml
Output00002.xml
etc.

After i split input 1, want to split the file input 2.
The problem is that the output files are overwritten by this output.

So i want to make the outputs from the different input files unique like:
Input1_output00001.xml
Input1_output00002.xml
Input2_output00001.xml
Etc.
So the files don't get overwritted.
There are no such things as libraries or something where i can put my code.
The code i use right now and whats works for splitting the files is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
split()
{
  CMarkup xmlInput, xmlOutput;
  xmlInput.Open( "FILEPATH.xml", MDF_READFILE );
  // open instead of load for large files
  int nObjectCount = 0, nFileCount = 400000;
   

  while ( xmlInput.FindElem("//BG:object") )
  {
    if ( nObjectCount == 0 )
    {
      ++nFileCount;
      xmlOutput.Open( "OUTPUT" + nFileCount + ".xml", MDF_WRITEFILE );
      xmlOutput.AddElem("BG:wplLk01 xmlns:BG=\"http://www.egem.nl/StUF/sector/bg/0310\" xmlns:StUF=\"http://www.egem.nl/StUF/StUF0301\"");
      xmlOutput.IntoElem();
      xmlOutput.AddElem("BG:stuurgegevens");
      xmlOutput.IntoElem();
      xmlOutput.AddElem("StUF:berichtcode","Lk01");
      xmlOutput.AddElem("StUF:zender");
      xmlOutput.IntoElem();
      xmlOutput.AddElem("StUF:organisatie","Organisation");
      xmlOutput.AddElem("StUF:applicatie","SORT");
      xmlOutput.OutOfElem();
      xmlOutput.AddElem("StUF:ontvanger");
      xmlOutput.IntoElem();
      xmlOutput.AddElem("StUF:organisatie","Organisation");
      xmlOutput.AddElem("StUF:applicatie","DLVY");
      xmlOutput.OutOfElem();
      xmlOutput.AddElem("StUF:referentienummer","123456789");
      xmlOutput.AddElem("StUF:tijdstipBericht","2015051914542378");
      xmlOutput.AddElem("StUF:entiteittype","WPL");
      xmlOutput.OutOfElem();
      xmlOutput.AddElem("BG:parameters");
      xmlOutput.IntoElem();
      xmlOutput.AddElem("StUF:mutatiesoort","T");
      xmlOutput.AddElem("StUF:indicatorOvername","V");
      xmlOutput.OutOfElem();
      xmlOutput.IntoElem();
    }
    xmlOutput.AddSubDoc( xmlInput.GetSubDoc() );
    ++nObjectCount;
	
    if ( nObjectCount == 1 )
    {
      xmlOutput.Close();
      nObjectCount = 0;
    }
  }
  
  if ( nObjectCount )
    xmlOutput.Close();
	xmlInput.Close();
  return nFileCount;
  }
Hello WesMekes,

I am not familiar with this type of code, but you might try this for line 14:

xmlOutput.Open( "OUTPUT" + nFileCount + ".xml", MDF_WRITEFILE | std::ios::app);

which opens the file for append.

Otherwise you could some research on this particular type of "open" to see what you can do.

Sorry its not much help,

Andy

P.S. After a little research you might find this useful:
http://www.cplusplus.com/forum/beginner/212586/
Last edited on
Topic archived. No new replies allowed.