strstream question

B

Bpb

I'm trying to use a string stored in a strstream object as the filename
parameter in the open call on an fstream object.. It requires a const
char* but no matter what I try I can't seem to get a raw pointer to the
string stored in the strstream object.. Anyone have an idea I'm overlooking?

Thanks in advance..
 
R

Ron Natalie

Bpb said:
I'm trying to use a string stored in a strstream object as the filename
parameter in the open call on an fstream object.. It requires a const
char* but no matter what I try I can't seem to get a raw pointer to the
string stored in the strstream object.. Anyone have an idea I'm overlooking?

You just call the str() method on it.

strstream ss;
ss << "x.txt";
fstream fstr(ss.str());

Calling str() freezes the stream.

strstreams are deprecated you know (in favor of stringstreams).

ostringstream foo;
foo << "x.txt";
fstream fstr(foo.str().c_str());
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top