Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

Substring in c++

#include <string>
#include <iostream>

int main() {
  std::string innerPlanets{"Mercury Venus Earth Mars"};

  // Copy 5 characters from position 8
  std::cout << innerPlanets.substr(8, 5) << "
";

  size_t begin = innerPlanets.find("Earth");
  // Copy characters from "Earth" to the end of the string
  std::cout << innerPlanets.substr(begin);
}
Source by cppbyexample.com #
 
PREVIOUS NEXT
Tagged: #Substring
ADD COMMENT
Topic
Name
1+8 =