Hi all,

I require some help using ifstream. I want to open a file who's name is made up in part by a user enter string - this is the format of the filename ...

"Airports_" << airlineICAO << ".txt"

i did try the following ...

ifstream airportsSource ("Airports_" << airlineICAO << ".txt");

How do i achieve this? Any help most appreciated.

I've also tried this with no luck ...

...

    string tempString1 = "Airports_";
    string tempString2 = airlineICAO;
    string tempString3 = ".txt";
    airportFileName = tempString1+tempString2+tempString3;

[B]    ifstream airportSource;
    airportSource.open(airportFileName);[/B]

/*    
    if (!airportsSource)
    { 
        cerr << "Could not open 'Airports_" << airlineICAO << ".txt' file!\n\n";
        system("PAUSE");
        exit (1);
    }

...

>airportSource.open(airportFileName);

ifstream::open() expects a C-style string as a parameter, not a C++ string. To convert a C++ string into a C-style string, use the c_str member function:

airportSource.open(airportFileName.c_str());

Thank you very much Joe !!!!!

I used

ifstream airportsSource(airportFileName.c_str());

works fine.

:)

This question has already been answered. Start a new discussion instead.