Computer Science Canada

MinGW Problem

Author:  BigBear [ Thu Apr 22, 2010 2:07 pm ]
Post subject:  MinGW Problem

I have been compiling code fine at school and I just installed the newest version of MinGW and it won't compile.

I was wondering if some major changes have been done in version 5.1.6.

Not sure what version I was using at school.

I am having a problem with

code:

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

using namespace std;

ifstream myFile;
myFile.open (_fileName);


code:

myFile.open (_fileName);
error: no matching function for call to `std::basic_ifstream<char, std::char_traits<char> >::open(std::string&)'

Author:  TerranceN [ Thu Apr 22, 2010 3:05 pm ]
Post subject:  RE:MinGW Problem

I can see in the error that _fileName is a string, and ifstream.open() does not accept strings. You need to convert it to a c-string (which is just an array of chars) using string's c_str() method (so use _fileName.c_str() instead of just _fileName). Hope that helps.

Author:  Euphoracle [ Thu Apr 22, 2010 4:15 pm ]
Post subject:  RE:MinGW Problem

Didn't I already tell you this on irc...

Author:  BigBear [ Thu Apr 22, 2010 4:23 pm ]
Post subject:  RE:MinGW Problem

Alright thanks that fixed it. I wonder why it worked at school...


: