ファイルの読み込み

This commit is contained in:
2026-05-04 22:58:23 +09:00
parent 9398075296
commit c73caa1867
3 changed files with 51 additions and 0 deletions

21
LICENSE.md Executable file
View File

@@ -0,0 +1,21 @@
# 076 Free License
Copyright (c) テクニカル諏訪子
Permission is hereby granted to any person obtaining a copy of the software
LibJpeg (the "Software") to use, modify, merge, copy, publish, distribute,
sublicense, and/or sell copies of the Software, subject to the following conditions:
1. **Origin Attribution**:
- You must not misrepresent the origin of the Software; you must not claim
you created the original Software.
2. **Notice Preservation**:
- This license and the above copyright notice must remain intact in all copies
of the source code.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

22
file.cc Executable file
View File

@@ -0,0 +1,22 @@
#include "file.hh"
#include <iostream>
#include <fstream>
vector<u8> read_file(const string &filename) {
std::ifstream file(filename, std::ios::binary | std::ios::ate);
if (!file) {
throw std::runtime_error("ファイルを開くに失敗: " + filename);
}
const auto size = file.tellg();
file.seekg(0);
vector<u8> data(static_cast<size_t>(size));
if (!file.read(reinterpret_cast<char *>(data.data()), size)) {
throw std::runtime_error("ファイルの読み込みに失敗。");
}
file.close();
return data;
}

8
file.hh Executable file
View File

@@ -0,0 +1,8 @@
#ifndef FILE_HH
#define FILE_HH
#include "types.hh"
vector<u8> read_file(const string &filename);
#endif // FILE_HH