Skip to main content

2.12) Strings In C++: Example


#include <string>
#include <iostream>
using namespace std;
int main()
{
  string word = "Maximum";
  cout << "Word: " << word << endl;
  cout << "Length: " << word.length() << endl;
  cout << "First three chars: " << word.substr(0, 3) << endl;
  cout << "Position of 'x': " << word.find("x") << endl;
  word.replace(0, 3, "Min");
  cout << "After replacing chars: " << word << endl;
  return 0;
}