fork(3) download
  1. #include <vector>
  2. #include <memory>
  3. #include <algorithm>
  4. #include <iostream>
  5.  
  6. int main()
  7. {
  8. using namespace std;
  9.  
  10. vector<size_t> v;
  11. v.push_back(1);
  12. v.push_back(2);
  13. v.push_back(3);
  14.  
  15. unique_ptr<char[]> p( new char[v.size() * sizeof(size_t)] );
  16.  
  17. // copy data from v into char array
  18. copy( reinterpret_cast<char *>(v.data()),
  19. reinterpret_cast<char *>(v.data()) + v.size() * sizeof(size_t),
  20. p.get() );
  21.  
  22. vector<size_t> w;
  23. w.resize(3);
  24.  
  25. // copy data from char array into w
  26. copy( p.get(), p.get() + v.size() * sizeof(size_t), reinterpret_cast<char *>(w.data()) );
  27.  
  28. for( size_t i = 0; i < w.size(); ++i ) {
  29. cout << w[i] << " ";
  30. }
  31. }
  32.  
Success #stdin #stdout 0s 3064KB
stdin
Standard input is empty
stdout
1 2 3