Created
March 28, 2020 12:23
-
-
Save namarium/c74178806f68bb9cc3389075395c0cb2 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 <cstdio> | |
#include <vector> | |
/// <summary> | |
/// バッファー作成 | |
/// </summary> | |
/// <param name="path">ファイルのパス</param> | |
/// <returns>バッファー(失敗時は、空)</returns> | |
std::vector<unsigned char> MakeBufferFromFile(const wchar_t* path) | |
{ | |
FILE *fileptr; | |
if (_wfopen_s(&fileptr, path, L"rb") != 0) { | |
return{}; | |
} | |
fseek(fileptr, 0, SEEK_END); | |
std::vector<unsigned char> buffer(ftell(fileptr)); | |
rewind(fileptr); | |
fread(buffer.data(), buffer.size(), 1, fileptr); | |
fclose(fileptr); | |
return buffer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment