fork download
  1. #include <iostream>
  2. #include <memory>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main(int argc, char* argv[])
  9. {
  10. vector<uint8_t> v0({'h', 'e', 'l', 'l', 'o' });
  11. vector<uint8_t> v1;
  12.  
  13. // pointer to the data
  14. // portion of the vector
  15. uint8_t* p0 = v0.data();
  16. uint8_t* p1 = v1.data();
  17.  
  18. // for stdout
  19. string s0(v0.begin(), v0.end());
  20. string s1(v1.begin(), v1.end());
  21.  
  22. cout << "s0='" << s0 << "' addr=" << &p0 << endl;
  23. cout << "s1='" << s1 << "' addr=" << &p1 <<endl;
  24.  
  25. /// here i would think the pointer to the data in v1
  26. /// would point to v0 and the pointer to the data in v0
  27. /// would be something else.
  28. v1 = move(v0);
  29.  
  30. p0 = v0.data();
  31. p1 = v1.data();
  32.  
  33. s0.assign(v0.begin(), v0.end());
  34. s1.assign(v1.begin(), v1.end());
  35.  
  36. cout << "s0='" << s0 << "' addr=" << (void *)p0 << endl;
  37. cout << "s1='" << s1 << "' addr=" << (char *)p1 << endl;
  38. }
  39.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
s0='hello' addr=0xbfeec2f0
s1='' addr=0xbfeec2f4
s0='' addr=0
s1='hello' addr=hello