• Advertisement
Sign in to follow this  

Yagh....ifstream

This topic is 4177 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having trouble getting this to compile.
boost::shared_ptr<model> model::loadmodel(const string filename)
{
    fstream file;
    file.open(filename);
It seems to want filename as a const char*, so how do I convert a string to an array of chars? I tried filename.c_str, but it thought that was <unknown type>

Share this post


Link to post
Share on other sites
Advertisement
filename.c_str() should work fine, or I suppose you could just make a char array and copy your string elements into it a character at a time...

Share this post


Link to post
Share on other sites
well, make the function parameter a const character array. and then when you call it you can just do: filename.c_str() in the call.

If you tried this, sorry.

Share this post


Link to post
Share on other sites
Quote:
Original post by NIm
I tried filename.c_str, but it thought that was <unknown type>

You probably forgot to #include <string>. filename.c_str() is the correct way to to it.

You shound probably pass your filename by reference rather than value (const string & filename) and open the file when you initialise it (fstream file(filename.c_str());), since this is more idiomatic C++.

Σnigma

Share this post


Link to post
Share on other sites
Yagh.... I'm a dumbass. I forgot the () to make c_str a function call. I had everything you suggested

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement