I have a string as "Bla bla *.h *.cpp *.png" . Now I want to put all the file names in vector. So my vector will have
vec[0] = "*.h"; vec[1] = "*.cpp"; vec[2] = "*.png"; So below is what I wrote.
void FileMgr::parseCmdLineForTextSearch(std::string b) { for (int i = 0; i < b.length(); i++) { std::size_t pos = b.find(" *."); std::cout << "pos:" << pos << "\n"; std::size_t pos_ = b.find(pos, " "); // this line does not // work, but I want to somehow get the position where // the blank space again started so that I can get the // the substring from **pos** to just before that blank space //thus giving me the exact end point of *.cpp or *.h std::string str2 = b.substr(pos, pos_); //^^ this pos_ will help // //me to get the required substring i.e, *.cpp or *.h patternVector.push_back(str); } } P.S: there might be other better way to implement it. But I somehow want to do it the way I mentioned above. Also I need to make sure that even if I am finding the end point of blank space it should always be after the whole text. I dont want to end up finding the blank space which is present in between the text bla bla.Is it possible?