C++ has a string class, but the C-Language does not.
Understanding C-style strings is important, even if you plan to use the string class.
C-style strings are arrays of characters (char).
C-style strings must adhere to this rule: everything that process a C-style string knows to process it character-by-character until the EOS ('\0') character.
In C/C++ arrays are related to pointers, so we will need a brief introduction.
string name;
string name("Cathy Bishop");
string name();
does NOT call the default constructor.
It is not even a declaration. What kind of statement is it?
Note: C/C++ has the same concept of primitives we saw in Java, such as int, char, double, ...; like Java, they do not have constructors and will not be used with dot-notation.
// Both of these declare an array of 12 characters
char *string1 = "this is fun";
char string2[12];
char *strptr;
// The string "Hi" is copied into string2 and printed
strcpy(string2, "Hi");
cout << string2 << endl;
// strptr is assigned the address of string1
strptr = string1;
// "this is fun" is printed twice
cout << strptr << endl;
cout << string1 << endl;
// what is printed next?
strptr = &(string1[8]);
cout << strptr << endl;
char *string1 = "this is fun";
char string2[7];
char *string3 = "Hello";
char *strptr = string2;
strcpy(string2, string3);
cout << string2 << endl;
cout << string3 << endl;
strcpy(strptr, string1);
strcpy(string1, string3);
cout << string2 << endl;
cout << strptr << endl;