Create new file

closed account (LE3bqMoL)
How do I create a new file
Like a txt file?
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <fstream>
using namespace std;
int main()
{

ofstream a_file("example.txt"); //this creates it. 
a_file << //use this to write to it.
ifstream b_file("example.txt"); //opens the file for reading
a_file >> //use this to read from it.

system("pause");
return 0;
}
Last edited on
note: You cannot read from an ofstream. An ifstream or fstream is needed.
oh yeah, sorry :/
in future, dont tell us what is happening, tell us why you are doing it atleast thats what i was told
who? me?
Wouldn't the "why" be "because I want to create a file"?

:oP
D
lol not you dval :P you mashed pwntato but sorry if your like a elite at C++ lol im amateur :P
Last edited on
I'm not advanced in c++. I haven't even worked with it for a week yet lol. but I was saying what was happening because it seemed self explanatory that way...If there is something you don't understand then by all means ask away :) I'll do my best to answer questions! sorry if it was confusing.

~Mashed Pwntato
Topic archived. No new replies allowed.