fork download
  1. #include <string>
  2. #include <vector>
  3. #include <iostream>
  4. #include <cstring>
  5. using namespace std;
  6.  
  7. int main() {
  8. vector<size_t> v;
  9. v.push_back(1);
  10. v.push_back(2);
  11. v.push_back(3);
  12.  
  13. string s((char*)(&v[0]), 3 * sizeof(size_t));
  14.  
  15. vector<size_t> w(3);
  16. strncpy((char*)(&w[0]), s.c_str(), 3 * sizeof(size_t));
  17.  
  18. for (size_t i = 0; i < w.size(); ++i) {
  19. cout << w[i] << endl;
  20. }
  21. }
Success #stdin #stdout 0s 3020KB
stdin
Standard input is empty
stdout
1
0
0