Open file for i/o
Hi guys! I have a problem writing code that must read and write into the same file. I don't know what I'm doing wrong. This is the sample code
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <fstream>
#include <iostream>
using namespace std;
int main() {
fstream file( "file", ios::binary | ios::app | ios::in );
file.put('a');
file.close();
return 0;
}
|
It must write 'a' character to the file but it isn't doing anything!
Any help will be greatly appreciated!!
-holtaf
Last edited on
Change ios::in to ios::out and (optionally) use an ofstream if you will only be doing output operations.
Thanks for the answer but I want to use the fie for reading and writing.And it seems I solved the problem .I changed the ios::app to ios::out
Topic archived. No new replies allowed.