codegurukool.com · Free coding tutorials & online compiler

Home › C++ Tutorial › C++ strings

C++ strings

The string class.

Include string. Join with +, use length(), substr, find, append and index with [].

Example code

#include <iostream>
#include <string>
using namespace std;
int main() {
  string s = "Hello";
  s += " World";
  cout << s << " " << s.length() << " " << s.substr(0, 5) << " " << s[1] << " " << s.find("World") << endl;
  return 0;
}

Run this code in the online editor

← C++ operators and booleansC++ math →