pentiumPunk wrote:
string fileName;
cout<<"Enter filename of datafile you wish to open \n";
cin>>fileName;
ifstream fin;
fin.open(fileName, ifstream::ios);
if(!fin)
{
cerr<<"blah blah blah";
exit(1);
}
i get this error message in VC++ .....Error C2664...on the
fin.open(fileName, ifstream::ios); line...cannot convert parameter 1 from
std::string to const char *
i cannot put a certain filename down such as fin.open("textfile.txt"), i
need the user to enter its name, for it will change.
Thanks alot in ahead!
1. As others have stated:
fin.open(filename.c_str());
or
ifstream fin(filename.c_str());
2. What kind of file mode is "ifstream::ios"?
Try a combination of: "ios_base::in", "ios_base::out",
or "ios_base::binary". The default mode for ifstream
is "ios_base::in" as a text file.
3. Don't use the exit() function. It has some nasty quirks to it.
Use the return statement instead.
4. Instead of returning a '1' from main() to the operating system,
use the predefined, portable constants EXIT_SUCCESS or
EXIT_FAILURE as defined in <cstdlib>.
5. You may want to change:
cin >> fileName;
to
getline(cin, filename, '\n');
The getline() function will read in the whole line. The other
expression _may_ not read in spaces or other characters.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book