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 :: print octal number in c++ 
Cpp :: c++ thread incide class 
Cpp :: convert letters to uppercase in c++ 
Cpp :: initialize string with length c++ 
Cpp :: how to sort vector of struct in c++ 
Cpp :: stoi() c++ 
Cpp :: sina + sinb formula 
Cpp :: c++ create thread 
Cpp :: cpp when use size_t 
Cpp :: 3d vector c++ resize 
Cpp :: c++ input 
Cpp :: how to know datatype of something in c++ 
Cpp :: new float array c++ 
Cpp :: c++ map insert 
Cpp :: c preprocessor operations 
Cpp :: c++ open file explorer 
Cpp :: Inner Section Sticky Scroll in elementor 
Cpp :: c++ compile to exe 
Cpp :: demonstrate constructor 
Cpp :: c++ split string by space into array 
Cpp :: cpp auto 
Cpp :: insert element in array c++ 
Cpp :: how to replace part of string with new string c++ 
Cpp :: run c++ program mac 
Cpp :: looping in map c++ 
Cpp :: how to check char array equality in C++ 
Cpp :: oncomponentendoverlap ue4 c++ 
Cpp :: z transfrom mathlab 
Cpp :: put function in cpp 
Cpp :: call function from separate bash script 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =