String Find in C++

Level 264 keystrokes

Uses find() to search for "World" in "Hello World" and prints the index where it starts, 6.

C++ code

// Stores "Hello World" in the string text
1string text = "Hello World";
// find() returns the index of the first match, or string::npos if none
// H=0 … space=5, so "World" starts at index 6
2cout << text.find("World") << endl;

Output

6
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this C++ code and how often they appear.

  • "× 4
  • <× 4
  • ;× 2
  • .× 1
  • (× 1
  • )× 1
  • =× 1

More C++ examples at level 2

← C++ typing practice