D
Dwight Army of Champions
Suppose I have an std::string called line that has the value
"sdsder>abc<gd<< sds". I want to get the substring between the greater-
than less-than signs and assign it to another std::string called
substr. How do I do this? My guess is that you should use two string
iterators, one called it_begin that points to the first occurrence of
a greater-than sign and another string iterator called it_end that
starts at the same spot as it_begin and goes to the first occurrence
of a less-than sign. Then you somehow extract the data between those
two iterators. Here's what I have so far:
#include <iostream>
#include <string>
int main()
{
std::string line = "sdsder>abc<gd<< sds";
std::string::iterator it_begin;
std::string::iterator it_end;
return 0;
}
Here's where I'm stumped. What value should I be assigning these two
iterators? Obviously their indexes need to be six and ten, but we need
to assume that line could be any string at all, not the garbage one
given. How do I tell std::string to "find the first occurrence of
character such-and-such and point it there"?
"sdsder>abc<gd<< sds". I want to get the substring between the greater-
than less-than signs and assign it to another std::string called
substr. How do I do this? My guess is that you should use two string
iterators, one called it_begin that points to the first occurrence of
a greater-than sign and another string iterator called it_end that
starts at the same spot as it_begin and goes to the first occurrence
of a less-than sign. Then you somehow extract the data between those
two iterators. Here's what I have so far:
#include <iostream>
#include <string>
int main()
{
std::string line = "sdsder>abc<gd<< sds";
std::string::iterator it_begin;
std::string::iterator it_end;
return 0;
}
Here's where I'm stumped. What value should I be assigning these two
iterators? Obviously their indexes need to be six and ten, but we need
to assume that line could be any string at all, not the garbage one
given. How do I tell std::string to "find the first occurrence of
character such-and-such and point it there"?