Getting a String Out of a String Stream (ostringstream) 
Author Message
 Getting a String Out of a String Stream (ostringstream)

Given:

    std::ostringstream ostr;

    ostr << "Result = ";
    ostr << DisplayCount;
    ostr << std::ends;

    SetDlgItemText(IDC_Message_Tx, ostr.str() );

error C2664: 'SetDlgItemTextA' : cannot convert parameter 2 from 'class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >' to 'const char *'  No user-defined-conversion
operator available that can perform this conversion, or the operator cannot
be called

Based on an example in Stroustrup (3rd Ed, pg 641), it looks like .str()
should return a string, but the error obviously says otherwise.  I have
tried assigning to a declared string variable  (MyString = ostr.str() ), but
that did not work either.  Suggestions?

Only marginally related, why is it that some class provide the auto-complete
list once you type the "." and some do not?

Thanks!

Don



Mon, 28 Feb 2005 01:47:55 GMT  
 Getting a String Out of a String Stream (ostringstream)
ostr.str().c_str()

--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> Given:

>     std::ostringstream ostr;

>     ostr << "Result = ";
>     ostr << DisplayCount;
>     ostr << std::ends;

>     SetDlgItemText(IDC_Message_Tx, ostr.str() );

> error C2664: 'SetDlgItemTextA' : cannot convert parameter 2 from
'class
> std::basic_string<char,struct std::char_traits<char>,class
> std::allocator<char> >' to 'const char *'  No user-defined-conversion
> operator available that can perform this conversion, or the operator
cannot
> be called

> Based on an example in Stroustrup (3rd Ed, pg 641), it looks like
.str()
> should return a string, but the error obviously says otherwise.  I
have
> tried assigning to a declared string variable  (MyString =
ostr.str() ), but
> that did not work either.  Suggestions?

> Only marginally related, why is it that some class provide the
auto-complete
> list once you type the "." and some do not?

> Thanks!

> Don



Mon, 28 Feb 2005 01:53:50 GMT  
 Getting a String Out of a String Stream (ostringstream)

Quote:

> Only marginally related, why is it that some class provide the auto-complete
> list once you type the "." and some do not?

I've always figured that it was crankiness in IntelliSense, which one
can only hope will improve in future versions (haven't used .net yet).
Then again, considering what's involved, I might as easily be amazed
that it works as well as it does.


Mon, 28 Feb 2005 02:33:47 GMT  
 Getting a String Out of a String Stream (ostringstream)


Fri, 19 Jun 1992 00:00:00 GMT  
 Getting a String Out of a String Stream (ostringstream)
Thanks Igor & Craig!

Don


Quote:
> Given:

>     std::ostringstream ostr;

>     ostr << "Result = ";
>     ostr << DisplayCount;
>     ostr << std::ends;

>     SetDlgItemText(IDC_Message_Tx, ostr.str() );

> error C2664: 'SetDlgItemTextA' : cannot convert parameter 2 from 'class
> std::basic_string<char,struct std::char_traits<char>,class
> std::allocator<char> >' to 'const char *'  No user-defined-conversion
> operator available that can perform this conversion, or the operator
cannot
> be called

> Based on an example in Stroustrup (3rd Ed, pg 641), it looks like .str()
> should return a string, but the error obviously says otherwise.  I have
> tried assigning to a declared string variable  (MyString = ostr.str() ),
but
> that did not work either.  Suggestions?

> Only marginally related, why is it that some class provide the
auto-complete
> list once you type the "." and some do not?

> Thanks!

> Don



Mon, 28 Feb 2005 03:33:07 GMT  
 Getting a String Out of a String Stream (ostringstream)


Fri, 19 Jun 1992 00:00:00 GMT  
 Getting a String Out of a String Stream (ostringstream)


Quote:
> Given:

<snip>

Quote:
> error C2664: 'SetDlgItemTextA' : cannot convert parameter 2 from 'class
> std::basic_string<char,struct std::char_traits<char>,class
> std::allocator<char> >' to 'const char *'  No user-defined-conversion
> operator available that can perform this conversion, or the operator
cannot
> be called

> Based on an example in Stroustrup (3rd Ed, pg 641), it looks like .str()
> should return a string, but the error obviously says otherwise.

No, it doesn't. The error says that you are trying to
pass a std::basic_string (string) to a function expecting
a const character pointer. They are not the same thing,
and the standard library doesn't include a conversion.

Igor's reply is correct.

Quote:
> Only marginally related, why is it that some class provide the
auto-complete
> list once you type the "." and some do not?

Auto-complete in VC is not completely dynamic, as it
is in VB. Some types are pre-defined in the auto-complete
data files, and due to function and operator overloading,
creating the necessary information is much more complex
and trouble-prone in C++.

Sometimes doing a "rebuild all" from the menu helps.



Mon, 28 Feb 2005 12:48:44 GMT  
 Getting a String Out of a String Stream (ostringstream)

Quote:
> Given:

>     std::ostringstream ostr;

>     ostr << "Result = ";
>     ostr << DisplayCount;
>     ostr << std::ends;

>     SetDlgItemText(IDC_Message_Tx, ostr.str() );

A minor side-note:  This (when fixed with .c_str()) only works in ANSI
builds.  There is a way to make this work in both ANSI and UNICODE builds.


Wed, 02 Mar 2005 00:36:58 GMT  
 Getting a String Out of a String Stream (ostringstream)

Quote:



> > Given:

> >     std::ostringstream ostr;

> >     ostr << "Result = ";
> >     ostr << DisplayCount;
> >     ostr << std::ends;

> >     SetDlgItemText(IDC_Message_Tx, ostr.str() );

> A minor side-note:  This (when fixed with .c_str()) only works in ANSI
> builds.  There is a way to make this work in both ANSI and UNICODE builds.

// Same as  ostringstream if TCHAR == char
// Same as wostringstream if TCHAR == wchar_t
typedef std::basic_ostringstream<TCHAR> tostringstream;

tostringstream ostr;

ostr << _T("Result = ");
ostr << DisplayCount; // ends shouldn't be necessary, I don't think.

SetDlgItemText(IDC_Message_Tx, ostr.str().c_str());



Wed, 02 Mar 2005 02:09:30 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. newbie needs help to strings, strings, strings

2. string streams

3. creating a string stream

4. Use String with Stream ?

5. Convert byte() or Binary Stream to base64 string

6. Read from stream and store into String

7. Q: redirect stream to string ?

8. file input stream buffer as string array!

9. stream i/o to strings?

10. String Stream Formatting

11. Wide string stream bug

12. string stream clear

 

 
Powered by phpBB® Forum Software