Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using c_str to convert to char* from ostringstream

Status
Not open for further replies.

thebarslider

Programmer
Dec 21, 2001
80
GB
I'm trying to convert a ostringstream to a char*.

I have so far managed to convert ostringstream to string but get errors when trying to convert to char* using
c_str();

below is my code:

GetLocalTime(&now);

std::eek:stringstream strstrm;
strstrm << now.wDayOfWeek << &quot;/&quot; << now.wDay
<< &quot;/&quot; << now.wMonth
<< &quot;/&quot; << now.wYear << &quot; &quot; << now.wHour << &quot;:&quot;
<< now.wMinute << &quot;:&quot; << now.wSecond << &quot;.mp3&quot;;

strstrm.str();
strstrm.c_str();

// Open/Create MP3 file to store output to
pFileOut = fopen( strstrm, &quot;wb+&quot; );

I recieve the following error on compilation:

C2039: 'c_str' : is not a member of 'std::basic_ostringstream<_Elem,_Traits,_Alloc>'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>
]

And therefore i cannot pass to fopen.
Is it possible to create a file using a string for filename? Could i bypass this conversion somehow?
I have tried to place c_str(); in scope by using:

strstrm.basic_string::c_str();

but still my code doesnt work.

I hope someone can help.

Any help will be much appreciated.

Mark.
 
change this:

strstrm.str();
strstrm.c_str();

to this:

string s = strstrm.str();
const char* sptr = s.c_str();

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top