Loading arbitrary files

Hi. Why can't I do:

class b
{
public:
b(string file)
{
filehandle.load(file);
}
private:
ifstream filehandle;
};

When I instanciate my object I get an error saying that it can't convert string to const char*. Thing is I want the user to type in the file he want's to load.
What am i doing wrong?
Added alla necessary #includes.
What is load?

Also, try using file.c_str(). It returns the string in the form of a const char*.
1
2
3
4
5
6
7
8
9
10
class b
{
public:
    b(string file)
        :    filehandle(file.c_str())
    {
    }
private:
    ifstream filehandle;
};


You really should initialise the object correctly at the start rather than instantiating a empty object then assigning it with stuff.
sorry. I of course meant filehandle.open(file). That did it. Thanks chewbob!!! was about to kill someone
Topic archived. No new replies allowed.