newbie

I try to write a simple program that writes something in a file like I saw in the input/output tutorial from your site.
Everything is compiling nicely but happens nothing with the file.
I thing that the program just doesn't know where to look for the file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
*
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile ("exercise.txt");
  if (myfile.is_open())
  {
    myfile << "This is a line.\n";
    myfile << "This is another line.\n";
    myfile.close();
  }
  else cout << "Unable to open file";
  cin.get();
  return 0;
}
Try this and tell us what happens:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile ("exercise.txt");
  if (myfile.is_open())
  {
    myfile << "This is a line.\n";
    myfile << "This is another line.\n";
    myfile << flush;
  }
  else cout << "Unable to open file";
  myfile.close();
  cin.get();
  return 0;
}
It happens absolutely nothing.
ofstream creates the file in the location next to the executable. Are you looking where the executable is?
Yes is there.
I've found it.
Thank you.
Topic archived. No new replies allowed.