File open error

I have an input file named "hello.tx." Meanwhile, I also have the input file opened. Everytime I compile and run th program I seem to get to get "
 file not opened 
on my dos screen. I did poshis question earlier too, but I'm not being able to understand whats causing this...

1
2
3
4
5
6
7
8
9
  void open_file (ifstream &fin)
{
	cout<<"Input File: Hello.txt";
	fin.open("Hello.txt");
		if(!fin)
		{
			cout<<"file not opened";
		}
}
Is open() failing because you are trying to open a file that's alreay opened?
Well when I have the input file opened on my console or either not opened it still says the same thing
it works fine in my compiler. Qt 5.2.1
I guess maybe it's because the file name inconsistence? hello and Hello.
ahh I don't know :( For some apparent reason, since I have download visual studio on my laptop nothing seems to be working perfectly or running. I'm assuming something is up with my complier...thank you for your resonse though
Maybe because the file is named "hello.tx" and you are trying to open "Hello.txt" file names are case sensitive.

Also you could try explictly calling [s]!fin.isOpen(); !fin.is_open();[/s] Actually ignore the second half because if it didn't open successfully it would put a fail bit for the operator!.
Last edited on
how did you call the function ?

works fine on mine

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <fstream>

void open_file( std::ifstream& file )
{
    std::cout << "Input file: Hello.txt\n";
    file.open( "Hello.txt" );
    file ?
        std::cout << "File open" : std::cout << "File not open";
}

int main()
{
    std::ifstream f;
    open_file( f );
}
Last edited on
Topic archived. No new replies allowed.