【发布时间】:2020-03-28 13:20:41
【问题描述】:
嗨,我需要做一些类似文件系统的事情,我需要从文件中读写(写函数工作)我有一个函数签名
void read(int addr, int size, char *ans);
void BlockDeviceSimulator::read(int addr, int size, char *ans) {
memcpy(ans, filemap + addr, size);
}
这是我从文件中读取并打印它的功能
std::string MyFs::get_content(std::string path_str) {
std::string ans;
//open file
BlockDeviceSimulator *newFile = new BlockDeviceSimulator(path_str);
newFile->read(1,newFile->DEVICE_SIZE,(char*)&ans);
std::cout << ans << std::endl;
delete newFile;
return "";
}
你能帮我这里出了什么问题以及为什么它不打印吗?
【问题讨论】:
-
ans.c_str()似乎合适。 -
不,因为我认为错误在于我调用读取地址但我不知道如何解决它