Answers for "select part of string cpp"

C++
16

c++ substring

// string::substr
#include <iostream>
#include <string>

int main ()
{
  std::string str="We think in generalities, but we live in details.";
                                           // (quoting Alfred N. Whitehead)

  std::string str2 = str.substr (3,5);     // "think"

  std::size_t pos = str.find("live");      // position of "live" in str

  std::string str3 = str.substr (pos);     // get from "live" to the end

  std::cout << str2 << ' ' << str3 << 'n';

  return 0;
}
Posted by: Guest on March-23-2020
1

splice string in c++

string str1 = "Apples are red";
string str2 = str1.substr(11, 3); // "red"
string str3 = str1.substr(0, 6); // "Apples"
Posted by: Guest on September-14-2020

Code answers related to "select part of string cpp"

Browse Popular Code Answers by Language