// Example of initializing C-style strings. // Example also illustrates output of strings. #include using namespace std; int main() { int i; char input[30]; char input2[30]; char greeting[6] = "Hello"; // leaving room for the null char char name[20] = "Marvin Dipwart"; // initializer string is smaller // than allocated space /* Now who really wants to count up the letters?? */ char str1[] = "The quick brown fox jumped over the lazy platypus"; /* Printing the strings. A couple ways */ cout << "\ngreeting = "; for (i = 0; i < 5; i++) // not preferred cout << greeting[i]; cout << "\nname = " << name << '\n'; cout << "str1 = " << str1 << '\n'; cout << "\nType an input string: "; cin >> input; cout << "\nType another input string: "; cin >> input2; // cin.getline(input2, 30); // a call that can read a whole sentence cout << "\nThe input string you typed: " << input << '\n'; cout << "\nThe another input string you typed: " << input2 << '\n'; return 0; }