fork download
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4. template <class T>
  5. void my_swap(T &a, T &b) {
  6. T aux;
  7. aux = a;
  8. a = b;
  9. b = aux;
  10. }
  11.  
  12. template <class T>
  13. void my_swap2(T *a, T *b) {
  14. T aux;
  15. aux = *a;
  16. *a = *b;
  17. *b = aux;
  18. }
  19.  
  20. int main(int argc, char const *argv[]) {
  21. //int a = 12,
  22. // b = 45;
  23.  
  24. //float a = 12.42,
  25. //b = 45.72;
  26.  
  27. //double a = 12.123,
  28. //b = 45.65;
  29.  
  30. //char a = 'x',
  31. // b = 'y';
  32.  
  33. string a = "adrian",
  34. b = "campanera";
  35. //char *a="Adrian",
  36. //*b="Campanera";
  37.  
  38. std::cout<<"a="<<a<<"\n";
  39. std::cout<<"b="<<b<<"\n";
  40.  
  41. //my_swap(a,b);
  42. my_swap2(&a,&b);
  43.  
  44. std::cout<<"Changed:\n";
  45. std::cout<<"a="<<a<<"\n";
  46. std::cout<<"b="<<b<<"\n";
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5464KB
stdin
Standard input is empty
stdout
a=adrian
b=campanera
Changed:
a=campanera
b=adrian