strtype1.cpp 975 B

12345678910111213141516171819202122232425262728
  1. // strtype1.cpp -- using the C++ string class
  2. #include <iostream>
  3. #include <string> // make string class available
  4. int main()
  5. {
  6. using namespace std;
  7. char charr1[20]; // create an empty array
  8. char charr2[20] = "jaguar"; // create an initialized array
  9. string str1; // create an empty string object
  10. string str2 = "panther"; // create an initialized string
  11. cout << "Enter a kind of feline: ";
  12. cin >> charr1;
  13. cout << "Enter another kind of feline: ";
  14. cin >> str1; // use cin for input
  15. cout << "Here are some felines:\n";
  16. cout << charr1 << " " << charr2 << " "
  17. << str1 << " " << str2 // use cout for output
  18. << endl;
  19. cout << "The third letter in " << charr2 << " is "
  20. << charr2[2] << endl;
  21. cout << "The third letter in " << str2 << " is "
  22. << str2[2] << endl; // use array notation
  23. // cin.get();
  24. // cin.get();
  25. return 0;
  26. }