Why isn't the file opening?

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 ()
{
  string line;
  fstream technologic ("daftpunk.bin", ios::out | ios::in | ios::binary);
  if (technologic.is_open())
  {
	cout << "It is open\n";
    technologic.close();
  }

  else cout << "Unable to open file\n"; 

  return 0;
}


Why isn't it opening the file?
try putting " technologic. open(("daftpunk.bin", ios::out | ios::in | ios::binary); " after ifstream technologic
I am currently working on ifstream in class and that is how I have my program set up and it opens. Hope it helps. I am just a beginner programmer,
It didnt work :/
I think you can't open with ios::in and ios::out try using ifstream.
did you change fstream technologic to ifstream or ofsteam. I think you have to initialize it as input or output. I enjoy reading and trying to figure things out so I learn as well. Hoping it will make me better.
Did you create the file daftpunk.bin?
i tried ifstream and ostream, and it didnt work, and I thought that if the file wasnt already made, it would make it for you?
I don't think it will if you pass ios::in
It looks like your fstream parameter is incorrect. You're trying to do input and output at the same time.

You can learn about fstream and file input/output in the Documentation Section: http://www.cplusplus.com/doc/tutorial/files/
I can see no problem with the original code; fstream can be used with both ios_base::in and iso_base::out. This is, in fact, its default open mode:
http://www.cplusplus.com/reference/iostream/fstream/open/

Where are you trying to create the file? You could try specifying a full path to your file and see if that makes a difference.
Topic archived. No new replies allowed.