-
ifstream error
I want the user to input a file name and then the program reads from that file and does what it needs to do.
Code:
cin >> file;
ifstream bookmark (file);
Before I was just using Code:
ifstream bookmark ("bookmarks.html")
but when I try and replace the actual file with a variable it gives me the error
Code:
.\CBookmarks.cpp(36) : error C2664: 'std::basic_ifstream<_Elem,_Traits>::basic_ifstream(const char *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'std::string' to 'const char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
-
You can't create a file from a string, because the "string" type was introduced very late in the C++ standard.
You can do Code:
ofstream bookmark(file.c_str());
--
Mats