SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct Element
  2. {
  3.     int int1;
  4.     int int2;
  5.     int int3;
  6. };
  7.  
  8. std:vector<Element> elements_to_write;
  9.  
  10. size_t vec_size = elements_to_write.size();
  11. out.write(reinterpret_cast<char*>(&vec_size), sizeof(vec_size));
  12. for(int i = 0; i < vec_size; i++)
  13. {
  14.     Element& el = elements_to_write[i];
  15.     out.write(reinterpret_cast<char*>(&el.int1), sizeof(el.int1));
  16.     out.write(reinterpret_cast<char*>(&el.int2), sizeof(el.int2));
  17.     out.write(reinterpret_cast<char*>(&el.int3), sizeof(el.int3));
  18. }
  19.  
  20. std:vector<Element> elements_to_read;
  21. size_t vec_size = 0;
  22. in.read(reinterpret_cast<char*>(&vec_size), sizeof(vec_size));
  23.  
  24. elements_to_read.reserve(vec_size);
  25.  
  26. for(int i = 0; i < vec_size; i++)
  27. {
  28.     Element el;
  29.     out.read(reinterpret_cast<char*>(&el.int1), sizeof(el.int1));
  30.     out.read(reinterpret_cast<char*>(&el.int2), sizeof(el.int2));
  31.     out.read(reinterpret_cast<char*>(&el.int3), sizeof(el.int3));
  32.     elements_to_read.push_back(el);
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top