fork download
  1. #include <iostream> /* C++ iostream C++98/11 */
  2. #include <string> /* C++ strings C++98/11 */ /* RegEx Boost */
  3. #include <boost/algorithm/string.hpp>
  4. int main() {
  5. std::string str = "\\dir\\dir2\\dir4\\dir4\\dir6";
  6. auto itr = boost::find_nth(str, "\\", 4);
  7. if(itr.empty()) std::cout << "empty";
  8. else std::cout << itr.begin() - str.begin();
  9.  
  10.  
  11. }
  12.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
19