Can't read file

Hi there,

So, I'm trying to read a file, but the file isn't opening... I have no ideia why, can't see any problem with what I've done...
I have a class Board and I read the file in the constructor like this:
1
2
3
4
5
6
7
8
9
10
11
  Board::Board(const string &filename)
{
	string file = filename;
	ifstream configuration;
	configuration.open(file.append(".txt"));

        if(configuration.fail())
           cout << "Error";

        //................
}


And in the main.cpp I do, for example, this:
 
  Board("t1");


Using this, it always triggers the "Error" message...
I have the file "t1" in the correct directory.
I really don't know what's wrong with this...
If anyone can help me, I would be really apreciated! :D
I have the file "t1" in the correct directory.

Are you sure. The file is located in the "current working directory"? Note that it's not necessary the same as the directory where the executable file is located and it can differ depending on how you start executing your program.

You are trying to open "t1.txt" so that must be the name of the file. If the file is named simply "t1" it will not work.
Topic archived. No new replies allowed.