Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 MinGW Problem
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
BigBear




PostPosted: 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&)'
Sponsor
Sponsor
Sponsor
sponsor
TerranceN




PostPosted: 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.
Euphoracle




PostPosted: Thu Apr 22, 2010 4:15 pm   Post subject: RE:MinGW Problem

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




PostPosted: Thu Apr 22, 2010 4:23 pm   Post subject: RE:MinGW Problem

Alright thanks that fixed it. I wonder why it worked at school...
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: