Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to get a section of a string in c++

// string::substr
#include <iostream>
#include <string>
using namespace std;

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

  str2 = str.substr (12,12); // "generalities"

  pos = str.find("live");    // position of "live" in str
  str3 = str.substr (pos);   // get from "live" to the end

  cout << str2 << ' ' << str3 << endl;

  return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: access the element of vector point2f c++ 
Cpp :: The smallest element from three 
Cpp :: C++ check if thread is joinable 
Cpp :: do c++ ints neeed to be initlaized 
Cpp :: cpp cout more than 1 value 
Cpp :: find the mminimum of the vector and its position in c++ 
Cpp :: inside information subtask 2 
Cpp :: std::hash 
Cpp :: C++ (gcc 8.3) sample 
Cpp :: copy constructor in c++ questions 
Cpp :: 1047. Remove All Adjacent Duplicates In String solution leetcode in c++ 
Cpp :: glm multiply vector by scalar 
Cpp :: why does the pointer value doesn;t change when I change it in funciton 
Cpp :: std 
Cpp :: Initialize Vector Iterator with begin() function 
Cpp :: c++ hsl to rgb integer 
Cpp :: C++: Methods of code shortening in competitive programming 
Cpp :: thread group c++ 
Cpp :: 1281. Subtract the Product and Sum of Digits of an Integer leetcode solution in c++ 
Cpp :: qt/c++ exception handler 
Cpp :: tic tac toe in cpp 
Cpp :: patterns in c++ 
Cpp :: convert ros time to double 
Cpp :: how to run a cpp file in visual studio 
Cpp :: main function 
Cpp :: add for input output file in c/c++ 
Cpp :: uses of c++ 
Cpp :: sinonimo de tratar 
C :: C bitwise integer absolute value 
C :: how to print something out to the console c 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =