Created
September 10, 2015 21:10
-
-
Save residentkrm/68d533cd0b9b02e7162d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdio> | |
#include <fstream> | |
#include <vector> | |
#include <conio.h> | |
int main() | |
{ | |
// prepare file | |
std::ofstream("d:/test.txt") << 1 << ' ' << 2 << '\n'; | |
std::FILE* f; | |
fopen_s(&f, "d:/test.txt", "r"); | |
std::vector<char> buf(4); // char is trivally copyable | |
std::fread(&buf[0], sizeof buf[0], buf.size(), f); | |
for (char n : buf) | |
std::cout << n; | |
std::vector<std::string> buf2; // string is not trivially copyable | |
// this would result in undefined behavior | |
// std::fread(&buf2[0], sizeof buf2[0], buf2.size(), f); | |
_getch(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment