Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- #include <vector>
- int main()
- {
- {
- std::vector<long> v = { 1, 2, 3, 4 };
- std::ofstream out("/tmp/test.bin", std::ios::binary);
- std::for_each(std::begin(v), std::end(v), [&out](const long& v) {
- out.write(reinterpret_cast<const char*>(&v), sizeof(v));
- });
- }
- {
- std::vector<long> v(4);
- std::ifstream in("/tmp/test.bin", std::ios::binary);
- std::for_each(std::begin(v), std::end(v), [&in](long& v) {
- in.read(reinterpret_cast<char*>(&v), sizeof(v));
- });
- for(const auto& n : v)
- std::cout << n << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement