fork(5) download
  1. #include <string>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. string fSplit(const string& fString)
  6. {
  7. size_t pos = fString.find(' '); // find first space
  8. if(pos == string::npos) // if no spaces were found
  9. return fString; // return the whole string
  10. else // otherwise
  11. return fString.substr(0, pos); // return the sub-string
  12. }
  13.  
  14. int main()
  15. {
  16. cout << fSplit("One two three four") << '\n';
  17. }
  18.  
Success #stdin #stdout 0.01s 2812KB
stdin
Standard input is empty
stdout
One