fstream file reading trouble

Running the program below will yelid an error saying the program file does not exist and in the line TestFile.open(name); it says that there is no matching function for call for the open method. This error is encountered in both the program i wrote below, and another example program from a textbook copied line for line into Eclipse. I am running Eclipse on Linux Mint 18.2 Cinnamon.

The issue goes away if i open a specific file rather than ask the user for a file name.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34


#include <iostream>
#include <fstream>
#include <string>

using namespace std;




int main()

{
	ifstream TestFile;

	string name;
	cout << "Enter Filename: ";
	cin >> name;

TestFile.open(name);


	TestFile.close();


	return 0;

}




Last edited on
It sounds like you are using an old compiler, or a recent one configured to use pre C++11 mode. If you can, change or configure the compiler.

A workaround is to pass a c-string which is easily done:
 
    TestFile.open(name.c_str());

Topic archived. No new replies allowed.