string - char *solved*
how would you do this (is there a pre-made functino for this) if not what kind of things could i do to store what a string = into a char whatever[];
[Edited by - raptorstrike on September 24, 2004 2:42:02 PM]
You mean like:
string MyString = "Stuff";
cout << MyString.c_str() << endl;
Or do you mean something else?
string MyString = "Stuff";
cout << MyString.c_str() << endl;
Or do you mean something else?
Constant string:
Pointer to string:
C++ string:
char msg[] = "Message"; // Size is automatic
Pointer to string:
char msg[256]; // MUST be large enough to hold text plus one byte!char *pString = "Message";strcpy(msg, pString);
C++ string:
char msg[256]; // Again, must have enough roomstd::string str("Message");strcpy(msg, str.c_str());
no i mean like
string something = "";
char whatever[6] = something;
oops just saw previous post
string something = "";
char whatever[6] = something;
oops just saw previous post
no you can't do that. You are assigning the pointer. Overload the '=' operator to do strcpy or something.
i know i cant do that thats why this thread is here i just want to know how to get something to that effect
Ah, then like it was said above use the method strcpy on 2 char arrays, or use the = operator on 2 std:string (make sure these are NOT pointers)
ok thanks alot you guys
wait from what i can tell im assigning
charArray[] to something
i want to do it the other way around
this is what i have so far
char scorestore[6];
char *pPrint;
string Print = strcpy(scorestore, pPrint);
wait from what i can tell im assigning
charArray[] to something
i want to do it the other way around
this is what i have so far
char scorestore[6];
char *pPrint;
string Print = strcpy(scorestore, pPrint);
Technically, the call to the std::string.c_str() method will give you access to the raw character bytes in the string.
You can then use this method to copy a std::string to a char[] array using the strcpy() function. Just make sure that you allocate enough memory for the copy.
You can then use this method to copy a std::string to a char[] array using the strcpy() function. Just make sure that you allocate enough memory for the copy.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement