C++ Why is file not being appended or overwritten? -


i trying make function takes array 'inputlayer[]' , stores each element in array in individual files. first time function called should create files , following times called should append new elements in inputlayer end of file.

if repeatedly storing single variable in single file use this:

fstream recordfile; recordfile.open ("inputrecord.txt", fstream::in | fstream::out | fstream::app); recordfile << inputlayer[0] << endl; 

in past has worked me have many variables i'd write individual files named "input_0_record.txt", "input_1_record.txt", ect.

in code below use stringstream create file names , use same method above write variables in files.

int recordinputvariables(double inputlayer[]) {       for(int = 0; < inputlayersize; ++)     {         stringstream ss;         ss << i;         string inputnumberstring = ss.str();         string recordfilename = "input_";         recordfilename.append(inputnumberstring);         recordfilename.append("_record.txt");         fstream inputrecordfile( recordfilename.c_str() );          inputrecordfile.open (recordfilename, fstream::in | fstream::out | fstream::app);         inputrecordfile << inputlayer[i] << endl;         inputrecordfile.close();      }      return 0; } 

however, when run file created , variable written file first time function called, subsequent times function called there no new variables written files.

i'm sure problem way i'm opening file. can spot i've done wrong?

 inputrecordfile.open (recordfilename, fstream::out | fstream::app); 

don't use fstream::in in context.


Comments