fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4. #include <cstdlib>
  5.  
  6. bool ParseHostIPPort(const std::string& hostURL, std::string& hostIP) {
  7. const char* colon = std::strchr(hostURL.data(), ':');
  8. if (colon == NULL) {
  9. return false;
  10. }
  11. hostIP = std::string(hostURL.data(), colon);
  12. return true;
  13. }
  14. int main()
  15. {
  16. std::string hostIP;
  17. if (ParseHostIPPort("abc:123", hostIP))
  18. {
  19. std::cout << hostIP << std::endl;
  20. }
  21. }
Success #stdin #stdout 0s 2964KB
stdin
Standard input is empty
stdout
abc