Hi friends,

I wrote a simple code to write in different files but I don't know where I made mistake. The function is writing the first file and after writing everything in the second file, not in the next files 3,4, 5. Can anyone help me please?

Thanks a lot!

int main()
{
 //...
 file1.open(name01Char);
 file1SECOND.open(name01SECONDChar );
 compare_Space(01,01SECOND, LOGFULL1, tokensA_1);
 01.close();
 01SECOND.close();
 01.open(name01Char);
 01SECOND.open(name01SECONDChar );
 compare_SpaceRed(01,01SECOND, LOGPARTIAL1 , tokensB_1);
 01.close();
 01SECOND.close();
 LOGPARTIAL1.close();
 LOGFULL1.close();
 // ---------------------------------------------------------
 file2.open(name02Char);
 file2SECOND.open(name02SECONDChar );
 compare_Space(02,02SECOND, LOGFULL2, tokensA_2);
 02.close();
 02SECOND.close();
 02.open(name02Char);
 02SECOND.open(name02SECONDChar );
 compare_SpaceRed(02,02SECOND, LOGPARTIAL2 , tokensB_2);
 02.close();
 02SECOND.close();
 LOGPARTIAL2.close();
 LOGFULL2.close();

 // ...
 // The same for 3,4 and 5
 // ...

 return 0;
}

 void compare_Space(ifstream &Firstfile, ifstream &SecondFile, ofstream &LOG_log, vector  <string> &tokens)
 {
  // ...
  LOG_log << "DEBUG PRINT" << endl;
  // ...
 }

don't use "01" and "02" as variable names.

Your IDE may have a handy find & replace feature to let you quickly change it too,
try hitting Ctrl + F.

Hi pseudorandom21,

I changed to file01 and file02. The problem is the same ... :(

as far as I know you can't name a variable starting with a number.

try clearing the error bits before opening a new file with a previous fstream.

i.e.,

//...
file01.close();
file01.clear();
file01.open("...");
//...

Thanks a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.