Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

std::string substr

/ string::substr (pos, len)
#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" (pos, len)							
  	
  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 << '
';
  return 0;
}

/*
* this will be the output :--
*	"think live in details."
*/
Source by cppbyexample.com #
 
PREVIOUS NEXT
Tagged: #substr
ADD COMMENT
Topic
Name
8+7 =