Compiler question

With the following code I get an error in bloodshed that I do not get in visual studio.

specifically this line : infile.open (inputFileName);

Bloodshed won't compile gives me an error but visual studio runs it fine

just curious why.





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

int main ()
{
int lineCount;
int letterCount [26];
char ch;
string inputFileName;

ifstream infile;
ofstream outfile;

cout << "please enter the file name";
getline (cin, inputFileName);
infile.open (inputFileName);

if (!infile)
{
cout << "cannot open the file" << endl;
return 1;

}

Last edited on
I've never used Bloodshed Dev-C++ but beginners who come to this forum almost all come here because of problems with the compiler. It's very out of date and has a lot of outstanding bugs that are not going to be fixed.

I see the same responses from all of the regulars here when facing this sort of problem: get a newer compiler.
This doesn't compile on Bloodshed because it's illegal code. You have to write infile.open(inputFileName.c_str());
infile.open(inputFileName); is available only in current C++.

infile.open( inputFileName.c_str() ); was the only one in earlier C++.

http://en.cppreference.com/w/cpp/io/basic_ifstream/open

Yes, get a newer compiler - one that some support for C++11.



Topic archived. No new replies allowed.