Answers for "taking substring from a string in cpp"

C++
0

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) << "n";

  size_t begin = innerPlanets.find("Earth");
  // Copy characters from "Earth" to the end of the string
  std::cout << innerPlanets.substr(begin);
}
Posted by: Guest on November-27-2021

Code answers related to "taking substring from a string in cpp"

Browse Popular Code Answers by Language