Save part of an string to another string, or an int

How do i save a parts of a string to another string, or to an int.
e.g.

1
2
string  bim= "1234567897899"
//Here i want  to save 899 to my temp string.. 



I've tried something like
for(int i= 9 ; i<13;i++)
temp[i] = bim[i]

But it says, that it's out of range.
Last edited on
Hi JohnJH,

about the conversion you can see these:
http://www.cplusplus.com/forum/articles/9645/

and about saving a part of a string you can use the std::string::substr function

1
2
3
string  bim= "1234567897899"
// the first parameter is where you want the function to start copying and the second is the last position.
string temp = bim.substr(10, 12);


the problem in your code is that you are trying to access a position out of range, you can't access the 13th position because there are only 12 position, the reason is that you string has 13 number but in c++ you start counting at 0, not 1.
Last edited on
Thank you :)
Topic archived. No new replies allowed.