/*
    See Nyhoff P228 for more details on strings class.
               
    http://www.cplusplus.com/reference/string/
    https://en.wikipedia.org/wiki/ASCII
*/

#include <iostream>           // Include cin / cout streams for input/output
#include <string>             // include string type
using namespace std;


int main()
{         
   string s;                  // Strings is an array of characters. (almost)

   cout << "Please enter string:";
   cin >> s;
   
   cout << "The length of the string is: " << s.length() << endl;

   for (int i=0;i<s.length();i++)
      {
         char c=s[i];
         cout << "s[" << i << "]=" << c << "  ascii " << int(c) << endl;
      }

// Somewhat more complicated string operations:

// Compare == 0 if the string matches the specifed string.
   if (s.compare("fisk")==0) cout << "You wrote fisk!\n";
   if (s.compare("hest")==0) cout << "You wrote hest!\n";

// Search for sub-string "ko" in s.
   int found=s.find("ko");
   if (found!=string::npos)
     {
        cout << "ko was found at position " << found << endl;
     }

   return 0;
}
