ERROR C2664

any idea why I am recieving this error?

void BankingSystem::loadFromFile()
{
string fileName;

cout << "\nEnter the filename (.txt): "; // user input
getline( cin, fileName ); // store as string
cin.sync();

// create stream for input
ifstream inAccounts_( fileName, ios::in | ios::binary );//ERROR C2664 Cannot convert parameter 1 from string to const char*

if ( !inAccounts_ )
{
cerr << "File could not be opened." << endl;
exit( 1 );
}

inAccounts_.seekg( 0 ); // read from beginning of file

Account client; // temp account object

// read first account
inAccounts_.read(reinterpret_cast< char * >( &client ),
sizeof( Account ) );

// add each account from file to vector
while ( !inAccounts_.eof() )
{
accounts_.push_back( client );

inAccounts_.read( reinterpret_cast< char * >( &client ),
sizeof( Account ) );
}

// inform user of successful load
cout << "\nFile " << fileName << " loaded successfully." << endl;

inAccounts_.close();
}
You are passing a string object to a function that expects a const char*. Just call the data() member of the string class.
thank you
Topic archived. No new replies allowed.