fstream not creating file

anybody have any idea why a file is not being created called haha.txt when I run this code?? am I missing something?

I'm running codeblocks

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()
{
    ifstream theFile("haha.txt");

    while(theFile.is_open()){
    string one;
    getline(cin,one);
    theFile >> one;
    cout << "file is open";
    }
}
An ifstream by default will not open a file that doesn't exist. If you want to create the file if it doesn't exist you'll need to use the correct open mode (app).

Because you're trying to read from the file. Reading from a file doesn't create files.
Topic archived. No new replies allowed.