...
Code Block | ||||
---|---|---|---|---|
| ||||
{ char data[BUFFERSIZE]; char append_data[BUFFERSIZE]; char *file_name; *// Initialize file_name and append_data */ fstream file( file_name, fstream::in | fstream::out | fstream::app); file << append_data << ends; file >> data; // ... } /*/ File gets closed here */ |
Compliant Solution (seekg
)
...
Code Block | ||||
---|---|---|---|---|
| ||||
{ char data[BUFFERSIZE]; char append_data[BUFFERSIZE]; char *file_name; *// Initialize file_name and append_data */ fstream file( file_name, fstream::in | fstream::out | fstream::app); file << append_data << ends; file.seekg(0, ios::beg); file >> data; // ... } //* File gets closed here */ |
Risk Assessment
Alternately inputting and outputting from a stream without an intervening flush or positioning call is undefined behavior.
...