fork download
  1. #include <iostream>
  2.  
  3.  
  4. template <typename T>
  5. struct some_other_allocator : std::allocator<T>{};
  6.  
  7.  
  8.  
  9. using other_string = std::basic_string<char, std::char_traits<char>, some_other_allocator<char>>;
  10.  
  11. int main() {
  12. other_string string1("hello");
  13.  
  14. //using std::string constructor
  15. std::string string2(string1.begin(),string1.end());
  16.  
  17. std::string string2_copy;
  18. //using std::copy
  19. std::copy(string1.begin(),string1.end(),std::back_inserter(string2_copy));
  20.  
  21. std::cout << string1 << std::endl;
  22. std::cout << string2 << std::endl;
  23. std::cout << string2_copy << std::endl;
  24. return 0;
  25. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
hello
hello
hello