code is:
vector<string> result;
string input = "Ellipse(50, 50, 200, 300)"
boost::split(result, input, boost::is_any_of("(, )"))
int i=0;
for (auto at=result.begin(); at != result.end(); at++)
cout << ++i << " " << *at << endl;
output is:
1 Ellipse
2 50
3
4 50
5
6 200
7
8 300
9
I want to get just Ellipse and integers, not empty space.
How can I get correct result?
input string can't be changed.
This will remove the empty spaces properly: erase_all(str1, " ");
.
Another alternative would be to use boost::token_compress_on
:
boost::trim_if(input, boost::is_any_of(" "));
boost::split(result, input, boost::is_any_of("(, )"), boost::token_compress_on);
This question was already asked: boost::split leaves empty tokens at the beginning and end of string - is this desired behaviour? and How to use boost split to split a string and ignore empty values?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.