Braden Y Braden Y - 11 months ago 55
C++ Question

Copying the elements of one vector into another

I need to copy the elements of one vector into another, but in the same process I need to be able to remove the comments or garbage from the data.
For example; two of the elements are

(* Month: 2005 01 *) 31
(* Month: 2005 02 *) 29

I need to get rid of the
(* Month: 2005 02 *)
and just move the
into the new vector. I can't seem to figure out how to do this in c++.

Answer Source


string str = "(* Month: 2005 01 *) 31";

you can find the last space

size_t p = str.find_last_of(" ");

then extract the substring you're interested in

string sub_str = str.substr(p+1)