creating files

FYI - i just started coding a few days ago so dont think im really stupid or something.

I am wondering if it is possible to create a file such as a .txt file using C++? If there is a way to do this please tell me.
Yes, you can write into a random named file and it will create that file for you in your default path (usually Desktop.) Is that what you mean?
yes that's what i mean. Could you explain how that is done?
http://www.cplusplus.com/doc/tutorial/files/

Simple example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// writing on a text file
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile ("example.txt");  //creating a stream
  if (myfile.is_open())                      //opening file and writing data
  {
    myfile << "This is a line.\n";
    myfile << "This is another line.\n";
    myfile.close();                            //closing file
  }
  else cout << "Unable to open file";
  return 0;
}
Topic archived. No new replies allowed.