No file created

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <fstream>
#include <string>


using namespace std;


int main()
{
	fstream myfile;
	
	myfile.open("test.txt", ios::out);
	myfile.close();
		
	return 0;
}


The code above creates a blank file named test.txt.
After that, I delete that file. I want to create a file and write the letter 'A' into it in binary mode. However, nothing happened. No file was created. Why is that?
This is the code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <fstream>
#include <string>


using namespace std;


int main()
{
	fstream myfile;
	char ch = 'A';
	
	myfile.open("test.txt", ios::out || ios::binary);
	myfile.write(&ch, sizeof(ch));
	myfile.close();
		
	return 0;
}
On line 14 you should use | instead of ||.
It works. Thank you very much.
Topic archived. No new replies allowed.