The usage of substr in C++

This article is reproduced from: https://www.cnblogs.com/cynthia-dcg/p/6182514.html Author: cynthia-dcg Please indicate the statement when reprinting.

Usage of substr function in C++

 1 #include<string> 
 2 #include<iostream> 
 3 using namespace std;
 4 
 5 void main() 
 6 { 
 7 string s("12345asdf"); 
 8 string a=s.substr(0,5);
 9 cout<<a<<endl;
10 }       

The above code obtains a string of length 5 from the 0th position in the string s. The default length is from the start position to the end

The output is:

12345

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324130276&siteId=291194637