开发者

Getting Stringstream to read from character A to B in a String

开发者 https://www.devze.com 2023-03-13 11:44 出处:网络
Is there some way to get StringStream to read charac开发者_开发问答ters A through B of 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号