Advertisement

ifstream

Started by May 16, 2002 08:14 PM
4 comments, last by Ragadast 22 years, 7 months ago
What type of variables does the ifstream function accept? It''s not working with strings.
ifstream isn''t a function, it''s a class. What is it that you are trying to do? If you are referring to the ifstream constructor, it can take a const char*.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Advertisement
I''m trying to call a function to load a file when i wish to. So i need to pass a variable with the file i want to open to ifstream, but it doesn''t work.
Uuuhh... Do you mean like this:
#include <fstream>#include <string>using namespace std;bool OpenSomeFile(string filename){    ifstream infile(filename.c_str(), ios::in | ios::binary);    if(infile.fail()){        return false;    }    .....    return true;} 


Hope that helps... the std::string member function c_str() returns a const char pointer to the string...

#define Email Lex & Yacc Function Pointers Virtual Terrain Knowledge Base Real Programmers
"Strong typing is for the weak minded!"
Go to http://www.cplusplus.com/ref/#libs
I hate signatures.
More links here: http://www.sgi.com/tech/stl/ STL is really neat and easy to use when you finally get to understand it.. I do think that Oluseyi will tell you the same.. The boost libraries are also useful (not standard, but useful)

This topic is closed to new replies.

Advertisement