I am writing a function that (if the file already exists) increases the number one by one and adding its parameters Work at the end of the file
Example:
- Attachments (49);
- Attachments (5,6);
File content 1: 1 \ n 4 \ n 9
file content at 2: 2 \ n 4 \ n 9 \ n 5 \ n 6
int attachment (int oz, int ojatepe) {ifstream infile; Infile.open ("stuff.txt"); If (infile.fail ()) {infile.close (); Offream outfile; Outfile.open ("stuff.txt"); Outfile & lt; & Lt; 1 & lt; & Lt; Andal & lt; & Lt; Obj & lt; & Lt; Andal & lt; & Lt; ObjType; Outfile.close (); } And {int length = 0; While (Infile.eof ()) {int temp; Infile & gt; & Gt; Temporary; Length ++; } Infile.close (); Infile.open ("stuff.txt"); Int fileContents [Length]; Int i = 0; While (Infile.eof ()) {/ * the program does not enter here * / infile & gt; & Gt; FileContents [i]; I ++; } Infile.close (); Offream outfile; Outfile.open ("stuff.txt"); FileContents [0] + = 1; (I = 0; i
The program does not enter the loop for a second time, so the content is never copied into the array and then in the file. I'm really sure what the problem is, or how to fix it, any help would be welcome. :)
Instead of closing the file and reopening (I'm not sure this operation reset Do not use the file position!) And just to start the file "Rewind"
infile.seekg (0, ios :: beg!)
No comments:
Post a Comment