Skip to main content
gamedev.net
🔒 Locked

C-String to String?

Started by Tonic151 Apr 11, 2002 at 10:24 PM 4 replies 450+ views
Original Post
Tonic151
Tonic151
How would i convert a C-String to a String
  

char test1[30];

to 

string test2;

  
I know stupid question...
GoofProg
GoofProg
string cppstring;
len..declare it
len=strlen(cstring);
slength.. declare it
for (slength=0; slength 'greater than'len; slength++)
{
cppstring+=cstring[slingth];
}





[edited by - GoofProg on April 11, 2002 11:46:25 PM]
The nightmare travels across the cosmos with his burning mane.  The trail of ash that is produced. ?Have a nice day!?
SabreMan
SabreMan
GoofProg: WTF are you on about? std::string provides a conversion ctor from const char*. Don''t make life hard.
Chem0sh
Chem0sh
As SabreMan was saying:


  
char test1[30];
std::string test2(test1);


There ya go!

"I will crush you with my bare hands and throw you into the wind!"

-Majin Vegeta
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
Tonic151
Tonic151
quote:
Original post by Chem0sh
As SabreMan was saying:



    
char test1[30];
std::string test2(test1);


There ya go!

"I will crush you with my bare hands and throw you into the wind!"

-Majin Vegeta



Thanks man, just something i was a little courious about off hand..

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.