Thread: I really could use some help

  1. #1
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133

    I really could use some help

    Hi.
    I wanted that I could typ in the name of the file I wanted to read/write but he gives me an error:

    Code:
    string LoadFileName;
    
    ifstream Checking ( LoadFileName );// Line 35
    Is it that he can't read/write a string as file name?

    Here is the error message:
    Code:
    35 C:\Documents and Settings\Admin\Bureaublad\Time\Time.cpp no matching function for call to `std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(std::string&)'
    
    note C:\Dev-Cpp\include\c++\3.4.2\iosfwd:90 candidates are: std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char, std::char_traits<char> >&)
    
    note C:\Dev-Cpp\include\c++\3.4.2\iosfwd:90                 std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
    
    note C:\Dev-Cpp\include\c++\3.4.2\iosfwd:90                 std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char, _Traits = std::char_traits<char>]

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The file stream classes take a const char* for the file name, so you just need to call the .c_str() function to pass one. It should be:

    ifstream Checking ( LoadFileName.c_str() );

  3. #3
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    Really really thanks, sorry for making a hole new thread but I didn't know where to search for.

Popular pages Recent additions subscribe to a feed