0

I have a C++ project that I haven't used in a year. It used to run perfectly, opening files with:

Matrix pmatrix;
    pmatrix.readFromFile("pmtx.txt");

and in the function:

void Matrix::readFromFile(string filename){

            ifstream tmfile;
            tmfile.open(filename.c_str());

            if (!tmfile) {
                cout << "unable to open tm file";
                //return 1;
            }

etc
}

It keeps telling me "unable to open tm file". I've been breaking my head about this. Obviously the file is in the directory of the src and I copied it to Debug and Release, I gave it full permissions. I use eclipse.

Any ideas why this just stopped working?

dorien
  • 5,265
  • 10
  • 57
  • 116
  • You could print your `args[0]` to get the current path of your programm. Maybe use `tmfile.is_open()` to check if file was opend successfully – al-eax Apr 26 '15 at 23:34
  • The strangest thing. If I do: cout << "path" << argv[0]; cout.flush(); right after int main(int argc, char *argv[]) { it outputs nothing, just the file open error (not even "path"). Could this be something else? – dorien Apr 26 '15 at 23:41
  • ok, I just copied the cpp and h files to a new project and it works. No idea what happened there... a clean did not help as well. Thanks thought for letting me realise it's not just a ifstream problem. – dorien Apr 26 '15 at 23:46
  • I am not sure if `cout` can print a `char*`, please try: `std::string s(args[0]);` and then `cout << s` – al-eax Apr 26 '15 at 23:47

1 Answers1

0

There was something strange screwed up with the eclipse project. I created a new project, copied in existing files and it worked.

dorien
  • 5,265
  • 10
  • 57
  • 116