string question

closed account (oLC9216C)
I have the position to start, and the length of the sting that I want
How can I get that string?
For example,
Hi, how are you?

how can I start getting the string with the word how, and the length of 5?
1
2
3
string mystring;
mystring="Hi, how are you?";
cout << mystring.erase(0,4) << endl;// Starting at 0, delete chars 4 
Last edited on
closed account (oLC9216C)
How about if I want to read the word between how and you?
Therefore i will get
, how are
Then you can string.erase more than once

mystring.erase(starting position,chars to delete)

1
2
3
mystring.erase(0,4); // delete 4 chars at start
mystring.erase(11,99); // delete 99 chars starting at position 11
cout << mystring;



Topic archived. No new replies allowed.