fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. std::string get_host_from_url(const std::string& url){
  5. int index = url.find("://");
  6. std::string host = "";
  7. cout <<index << endl;
  8. if(index >=0) {
  9. //host = url.substr(0, url.find("/"));
  10. //return host;
  11. //} else {
  12. const std::string& uin = url.substr(index+3);
  13. url = uin;
  14. cout << url << endl;
  15. } host = url.substr(0, url.find("/"));
  16. return host;
  17. }
  18.  
  19. int main() {
  20. // your code goes here
  21. std::string output = get_host_from_url("http://w...content-available-to-author-only...o.uk/path1/path2");
  22. cout << output <<endl;
  23. return 0;
  24. }
  25.  
Compilation error #stdin compilation error #stdout 0s 16064KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘std::__cxx11::string get_host_from_url(const string&)’:
prog.cpp:13:15: error: passing ‘const string {aka const std::__cxx11::basic_string<char>}’ as ‘this’ argument discards qualifiers [-fpermissive]
         url = uin;
               ^~~
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/bits/locale_classes.h:40,
                 from /usr/include/c++/6/bits/ios_base.h:41,
                 from /usr/include/c++/6/ios:42,
                 from /usr/include/c++/6/ostream:38,
                 from /usr/include/c++/6/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/6/bits/basic_string.h:565:7: note:   in call to ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
       operator=(const basic_string& __str)
       ^~~~~~~~
stdout
Standard output is empty