C++ Extract number from the middle of a string
问题 I have a vector containing strings that follow the format of text_number-number Eg: Example_45-3 I only want the first number ( 45 in the example) and nothing else which I am able to do with my current code: std::vector<std::string> imgNumStrVec; for(size_t i = 0; i < StrVec.size(); i++){ std::vector<std::string> seglist; std::stringstream ss(StrVec[i]); std::string seg, seg2; while(std::getline(ss, seg, '_')) seglist.push_back(seg); std::stringstream ss2(seglist[1]); std::getline(ss2, seg2,