fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. void getname_value(std::string name)
  5. {
  6. std::cout << "name in getname_value: " << &name << '\n' ;
  7. std::getline(std::cin, name) ;
  8. }
  9.  
  10. void getname_ref(std::string& name)
  11. {
  12. std::cout << "name in getname_ref: " << &name << '\n' ;
  13. std::getline(std::cin, name) ;
  14. }
  15.  
  16.  
  17. int main()
  18. {
  19. std::string name ;
  20.  
  21. std::cout << "name in main: " << &name << '\n' ;
  22.  
  23. getname_value(name) ;
  24. std::cout << "After getname_value name is \"" << name << "\"\n" ;
  25.  
  26. getname_ref(name) ;
  27. std::cout << "After getname_ref name is \"" << name << "\"\n" ;
  28. }
Success #stdin #stdout 0s 3480KB
stdin
jeff
george
stdout
name in main: 0xbf9c28a8
name in getname_value: 0xbf9c28ac
After getname_value name is ""
name in getname_ref: 0xbf9c28a8
After getname_ref name is "george"