convert TDesC8 to Open C string

Login to reply to this topic.
Thu, 2008-05-08 08:44
Joined: 2007-11-14
Forum posts: 1

Hi,

I want to convert my TDesC8 (Symbian string) to std::string (Open C string)!
I use this code:
---
TInt x = aCustomMessage.Length();
td::string* str = new(ELeave) std::string[x+1];
Mem::Copy(str, get_episode->Ptr(), x);
---
In TDesc8 string is ch2_id, str value is c0h020 !

WHY??? Puzzled

Thx the answers!


Thu, 2008-05-08 11:01
Joined: 2006-05-08
Forum posts: 152
Re: convert TDesC8 to Open C string

bakosa,

Your code looks pain wrong for various reasons. First of all, why bother allocating std::string on the heap? Sencondly, std::string is NOT char*, so you can't simply use memcpy on it.

I haven't used STL on Symbian, but I guess the correct way would be:

std::string str(get_episode.PtrZ(), get_episode.Length());

Or even

std::string str(get_episode.PtrZ());

Obviously, the former is more efficient. As simple as that.

Please see the std::string docs at http://www.sgi.com/tech/stl/basic_string.html

Thu, 2008-05-08 11:23
Joined: 2004-11-29
Forum posts: 1134
Re: convert TDesC8 to Open C string

What confuses me the most is why you think that std::string has anything to do with Open C...

std::string is C++ STL...

Also, from what you describe, I doubt you are using a TDesC8, sounds more like a TDesC16 with the every-second-byte-being-zero thing.

  • Login to reply to this topic.