nact: Change tvar from char array to std::string

This commit is contained in:
kichikuou
2025-06-06 14:51:38 +09:00
parent aef2822bc4
commit 7f527da74f
12 changed files with 50 additions and 57 deletions
+15
View File
@@ -5,6 +5,7 @@
*/
#include "fileio.h"
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -89,3 +90,17 @@ std::string FILEIO::gets()
}
return s;
}
std::string FILEIO::read_string(size_t size) {
std::vector<char> buf(size + 1);
if (fread(buf.data(), size, 1, fp) != 1) {
return std::string();
}
return std::string(buf.data());
}
bool FILEIO::write_string(const std::string& str, size_t size) {
std::vector<char> buf(size);
memcpy(buf.data(), str.c_str(), std::min(size, str.size()));
return fwrite(buf.data(), size, 1, fp) == 1;
}