Archived

This topic is now archived and is closed to further replies.

johnnyBravo

How to convert std::string to char array?

Recommended Posts

Guest Anonymous Poster
quote:
Original post by Deficite
Haven''t tested, but this should work:
strcpy(cString, sString.c_str());

That would work, but mine was better. If a C string manip routine doesn''t have an "n" in the name, don''t use it.

Share this post


Link to post
Share on other sites
its compiles and all and doesnt crash, but it seems to return nothing...im opening a file and reading a line with fstream, maybe im not reading the file properly.

Also im displaying it with dx so thats y i need the char...

Share this post


Link to post
Share on other sites
quote:
Original post by rpg_code_master
is it not cString = sString.data( );
"Returns a pointer to an array of characters (not necessarily null-terminated) representing the string''s contents."

C strings must be null-terminated. And that wouldn''t make a copy but only point to sString''s internals.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by johnnyBravo
its compiles and all and doesnt crash, but it seems to return nothing...im opening a file and reading a line with fstream, maybe im not reading the file properly.

Maybe not, but how would we know? Show us the code.

Or even better: Learn how to use the debugger. Seriously. It will save you huge amounts of pain, frustration and time.

Share this post


Link to post
Share on other sites
oh no dont worry, it was, i ended up copying a fstream example and it worked, im not sure what i did, but ahwell!

Yeah recently i worked out in vc6++ u can double click on errors and it goes to it!

[edited by - johnnyBravo on October 21, 2003 5:28:48 AM]

Share this post


Link to post
Share on other sites