#include // std::ifstream, std::ofstream
#include
using namespace std;
int main() {
std::fstream outfile/*("new.txt", std::ofstream::binary | std::ofstream::app)*/;
outfile.open("new.txt", fstream::binary | fstream::out | fstream::app | fstream::in/*ios::app*//* ios::out | ios::ate | ios::binary, _SH_DENYNO*/);
char* buffer_0 = new char[50];
if (outfile.is_open()) {
outfile.seekp(3, ios::beg);
//读没问题,是按照指针在的位置开始读取的
// outfile.read(buffer_0, 50);
// for (int i = 0; i < 50; ++i) {
// std::cout << *(buffer_0 + i);
// }
// std::cout << std::endl;
//为什么写有问题
outfile.write("c", 2);
outfile.close();
}
delete[] buffer_0;
return 0;
}
222
55
333
33
4c

函数,写入数据是写入到文件结尾。
如果你想在任意位置写入字符,你去掉app
https://en.cppreference.com/w/cpp/io/basic_filebuf/open