fork(4) download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4.  
  5. std::string GetNthWord(std::string s, std::size_t n)
  6. {
  7. std::istringstream iss (s);
  8. while(n-- > 0 && (iss >> s));
  9. return s;
  10. }
  11.  
  12. int main()
  13. {
  14. std::cout << GetNthWord("I hope that you can figure out how this works.", 4) << std::endl;
  15. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
you