I have the following code:
string str1 = "first string";
string str2(str1, 6, 6)
// Output: string
- 1st param points to the variable which has to be sliced
- 2nd param tell the starting index (starting from 1)
- 3rd param tells how many characters you want to take from str1 - basically the ending index
I understand all of the above. However, when I came across the below code block I got very confused.
Why does this work? It doesn't have 3 params.
string str3(str1.begin(), str1.begin() + 5); // Why no 3rd param ?
// Output: first
Also here, the 2nd param goes till the 5 index as opposed to starting from there (like in the first example). Can someone explain what's different b/w code blocks 1 and 2?
Thank you.
std::stringhas multiple overloads