I recomend using the STL string library....
Code:#include <string> using namespace std; //do not include .h for the stl string library int main() { string p1, p2, p3; p1 = "this is"; p2 = "a test"; p3 = p1 + " " + p2; cout << p3; return 0; }
there are quite a bit of functions for the string datatype..:
those are the most common ones..Code:stringname.length(); //returns the length stringname.c_str(); //returns the c_style string, with the null char at the end. stringname.substr(s,f); //gets a substring from point s with //the length of f
and here is the header for the strcpy() function, you only use it for character arrays, or pointers to character arrays(which are essentially the same thing).
Code:char *strcpy( char *strDestination, const char *strSource );
PS:
the reason + works with the string datatype, is because it is overloaded, so it can add strings.....
<edited: I made a little mistake when explaining the substr() function... but it's fixed now>
[Edited by denniswrenn on 12-21-2000 at 06:09 AM]




Reply With Quote