Can we convert the RWCString to std::string? If yes how?

V

varsha.gadekar

I want to convert the message of type RWCString to std::string type.
How can we do this?
 
O

Ondra Holub

(e-mail address removed) napsal:
I want to convert the message of type RWCString to std::string type.
How can we do this?

Since RWCString is not C++ standard class, there is no C++ standard way
how to do it. I do not know RWCString, so I can only guess:

- look into RWCString documentation and try to find there some
converting function
- there may be also some method, whcih gives the buffer occupied by
RWCString. This may be used as one input parameters for std::string
- if RWCString can be written into output stream, you can srite it to
std::eek:stringstream and get the string with method str() from there
 
J

Jim Langston

I want to convert the message of type RWCString to std::string type.
How can we do this?

I googled for RWCString, and see it has an operator char*. So:
std::string MyString( RWCString );
*should* work.
 
V

varsha.gadekar

Thanks to you both it is working. But i need to check if it works for
large message stream
..
 
F

Frank Potter

then read a very large text file and test it,
it's easy to find out if it works for huge strings.
 
M

Mehturt

Jim said:
I googled for RWCString, and see it has an operator char*. So:
std::string MyString( RWCString );
*should* work.

This won't work if the string contains character with ascii value 0.
In this case you need the length of RWCString as well.
 
S

Satish

You can use the data() function of RWCString class to get char *

RWCString testString("Hellow")
cout << testString.data()

You can use this further to initialise std::string objects. Hope this
helps.
 
B

BobR

Frank Potter wrote in message ...
then read a very large text file and test it,
it's easy to find out if it works for huge strings.

Do not top-post!

{
std::string Tst("");
std::cout<<"Tst.max_size()="<<Tst.max_size()<<std::endl;
}
 

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

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top