substr in c++
C++
// 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;
}String is: cat
// CPP program to illustrate substr()
#include <string.h>
#include <iostream>
using namespace std;
int main()
{
// Take any string
string s1 = "Geeks";
// Copy three characters of s1 (starting
// from position 1)
string r = s1.substr(1, 3);
// prints the result
cout << "String is: " << r;
return 0;
}
// CPP program to illustrate substr()
#include <string.h>
#include <iostream>
using namespace std;
int main()
{
// Take any string
string s = "dog:cat";
// Find position of ':' using find()
int pos = s.find(":");
// Copy substring after pos
string sub = s.substr(pos + 1);
// prints the result
cout << "String is: " << sub;
return 0;
}
String is: eek
Also in C++:
- Title
- unordered_map c++ insert
- Category
- C++
- Title
- ios_base::sync_with_stdio(false);cin.tie(NULL);
- Category
- C++
- Title
- how to delete a node c++
- Category
- C++
- Title
- c++ append to list
- Category
- C++
- Title
- initialise 2d vector in c++
- Category
- C++
- Title
- coping 2d vector in cpp
- Category
- C++
- Title
- c++ function to find length of array
- Category
- C++
- Title
- split 2d array into chunks in c++
- Category
- C++
- Title
- c++ map insert
- Category
- C++
- Title
- SFML window
- Category
- C++
- Title
- mingw32/bin/ld.exe: C:\Users\mfrom\AppData\Local\Temp\ccSKcRks.o:PizzaPi.cpp:(.text$_ZN5PizzaC2Ev[__ZN5PizzaC2Ev]+0xa): undefined reference to `vtable for Pizza' collect2.exe: error: ld returned 1 exit status
- Category
- C++
- Title
- c++ char to string
- Category
- C++
- Title
- c++ code for polynomial addition
- Category
- C++
- Title
- Arrays hackerrank solution in c++
- Category
- C++
- Title
- c++ overloaded equality check operator
- Category
- C++
- Title
- how to sort an array c++
- Category
- C++
- Title
- sort a pair using c++ stl
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- how to output to console c++
- Category
- C++
- Title
- delay millis arduino
- Category
- C++
- Title
- 2d vector
- Category
- C++
- Title
- time function c++
- Category
- C++
- Title
- arrow operator c++
- Category
- C++
- Title
- elseif c++
- Category
- C++
- Title
- how initilaize deffult value to c++ class
- Category
- C++
- Title
- find in vector in c++
- Category
- C++
- Title
- constant variables in c++
- Category
- C++
- Title
- length of 2d array c++
- Category
- C++
- Title
- c++ multidimensional vector
- Category
- C++
- Title
- sfml basic program
- Category
- C++
- Title
- fail() in c++
- Category
- C++
- Title
- floor() in c++
- Category
- C++
- Title
- how to import getline in c++
- Category
- C++
- Title
- error: ‘memset’ was not declared in this scope in cpp
- Category
- C++
- Title
- c++ triple
- Category
- C++
- Title
- class is replace by structure
- Category
- C++
- Title
- find all the palindrome substring in a given string
- Category
- C++
- Title
- c++ typedef
- Category
- C++
- Title
- loop c++
- Category
- C++
- Title
- pop_back
- Category
- C++
- Title
- delete files c++
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- check if key exists in map c++
- Category
- C++
- Title
- c++ ternary operator
- Category
- C++
- Title
- how to append an element to an array in cpp
- Category
- C++
- Title
- how to get input from the console in c++
- Category
- C++
- Title
- double to float c++
- Category
- C++
- Title
- stl sort in c++
- Category
- C++
- Title
- hashing in competitive programming
- Category
- C++
- Title
- function for searching in map in c++
- Category
- C++
- Title
- c++ find object in vector by attribute
- Category
- C++
- Title
- c++ looping through a vector
- Category
- C++
- Title
- how to sort in descending order c++
- Category
- C++
- Title
- c++ dereference a pointer
- Category
- C++
- Title
- bool function in c++
- Category
- C++
- Title
- cpp create lambda with recursion
- Category
- C++
- Title
- c++ overloaded == operator
- Category
- C++
- Title
- built in popcount c++
- Category
- C++
- Title
- c++ overload operator
- Category
- C++
- Title
- find in string c++
- Category
- C++
- Title
- accumulate in cpp
- Category
- C++
- Title
- check an stack is empty c++
- Category
- C++
- Title
- c++ movment
- Category
- C++
- Title
- abs in c++
- Category
- C++
- Title
- c++ evaluate expression
- Category
- C++
- Title
- cin.ignore
- Category
- C++
- Title
- what is iterator in c++?
- Category
- C++
- Title
- cut by delimiter c++
- Category
- C++
- Title
- substr in c++
- Category
- C++
- Title
- string to vector c++
- Category
- C++
- Title
- split string at index c++
- Category
- C++
- Title
- how to cin multiple lines of strings c++
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++
- Title
- pause the console c++
- Category
- C++
- Title
- regexp_like oracle c++
- Category
- C++
- Title
- initialization list c++
- Category
- C++
- Title
- never gonna give you up
- Category
- C++
- Title
- c++ how to return an empty vector
- Category
- C++
- Title
- c++ sort array of ints
- Category
- C++
- Title
- how to make a n*n 2d dynamic array in c++
- Category
- C++
- Title
- how to create a vector in c++
- Category
- C++
- Title
- Rectangle area hackerrank solution in c++
- Category
- C++
- Title
- declare vectors c++
- Category
- C++
- Title
- how to decalre a string in c++
- Category
- C++
- Title
- setbits
- Category
- C++
- Title
- error: redefinition of ‘class Customer’
- Category
- C++
- Title
- double to int c++
- Category
- C++
- Title
- how to initialize 2d vector of any size
- Category
- C++
- Title
- min in vector c++
- Category
- C++
- Title
- find vector in c++
- Category
- C++
- Title
- How to find the kth smallest number in cinstant space
- Category
- C++
- Title
- free or delete in c++
- Category
- C++
- Title
- switch case sinax c++
- Category
- C++
- Title
- c++ read file line by line
- Category
- C++
- Title
- recursive in c++
- Category
- C++
- Title
- c++ replace substrings
- Category
- C++
- Title
- do while loop c++
- Category
- C++
- Title
- empty string c++ value
- Category
- C++
- Title
- catalan number calculator
- Category
- C++
- Title
- findung the mode in c++
- Category
- C++