Reputation: 2797
This is my C++ code.
int main(){
string str("xxxxx 250 15");
string data(str,10,13);
cout<<data;
return 0;
}
Here I need to get value "250 " from the above string. My total string size is 16. After running this program I got the below output.
250 15. But I gave index to get only "250 ". But I'm getting wrong answer. It give me a result until the end of the string. Why I'm getting the result "250 15" ?
Upvotes: 0
Views: 1945
Reputation: 258548
10,13
is wrong, you're not supposed to give it a range, but the start and number of characters - i.e. 10,3
- starting from character 10, give me 3 characters.
string data(str,10,3);
Upvotes: 5