Search
 
SCRIPT & CODE EXAMPLE
 

CPP

cpp string slice

//Time complexity: O(n)

//Auxiliary Space: O(n)

#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(3, 2);
 
 	// Copy substring after pos
	string sub = s.substr(pos + 1);
	
	// Copy substring before pos
    string sub = s.substr(0 , pos);
    
    // prints the result
    cout << "String is: " << r;
 
    return 0;
}
Comment

c++ string slicing

// 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(3, 2);
 
    // prints the result
    cout << "String is: " << r;
 
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ function as paramter 
Cpp :: C++ Infinite while loop 
Cpp :: quicksort 
Cpp :: demonstrate constructor 
Cpp :: c++ doubly linked list 
Cpp :: travelling salesman problem c++ 
Cpp :: joining two vectors in c++ 
Cpp :: c++ preprocessor operations 
Cpp :: std::count() in C++ STL 
Cpp :: maxheap cpp stl 
Cpp :: resize string c++ 
Cpp :: c++ remove chars from string 
Cpp :: c++ how to return an empty vector 
Cpp :: c++ function of find maximum value in an array 
Cpp :: tuple vector c++ 
Cpp :: opencv c++ feature detection 
Cpp :: selection sort c++ 
Cpp :: c++ loop trhought object 
Cpp :: prevent copy c++ 
Cpp :: UENUM ue4 
Cpp :: how to traverse through vector pair 
Cpp :: accumulate in cpp 
Cpp :: add input in c++ 
Cpp :: Abstract factory C++ code 
Cpp :: maximum subarray leetcode c++ 
Cpp :: time complexity of best sort algorithm 
Cpp :: use set to get duplicates in c++ 
Cpp :: How to generate all the possible subsets of a set ? 
Cpp :: pointer to pointer c++ 
Cpp :: pause the console c++ 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =