Getting Stringstream to read from character A to B in a String
Is there some way to get StringStream to read charac开发者_开发问答ters A through B of a string?
For example, something like (but not):
stringstream mystringstream;
mystringstream.read(char* s, streamsize n, **int firstcharacter**);
Thanks for your help.
EDIT: By A through B I mean, for example, the third through fifth characters.
EDIT: Example: get characters three through five of "abcdefghijklmnop" would give "cde".
or, if you need a substring in position A through B, you can do
string s = mystring.substr(A, B-A+1); // the second parameter is the length
if this must be a stringstream, you can do
string s = mystringstream.str().substr(A, B-A+1);
You can use the substr
-method:
std::string foo = "asdfersdfwerg";
std::cout << foo.substr(5, 4) << std::endl;
This will print rsdf
.
精彩评论