为了账号安全,请及时绑定邮箱和手机立即绑定

多线程文件读写

多线程文件读写

C++ C C#
慕村2513822 2017-08-23 17:23:50
如何用双线程对这个文件进行同步写读?#include <iostream>#include <fstream>#include<windows.h>#include<ctime>#include<vector>#include<mutex>using namespace std;vector<string>vtData = { "123","dfdfdfdfd","123","dfdfdfd"};FILE*f = nullptr;long writePos = 0;size_t writeLen = 0;condition_variable writeOK;condition_variable writeOK;mutex m;void writeToFile() { //写一行 for (size_t i = 0; i < vtData.size(); i++) { //vtData[i];//写入文件 writePos = ftell(f); writeLen = vtData[i].length(); fwrite( ); fflush(f); }}void readFromFile() { char*s = new char[writeLen + 1]; fseek(f, writePos, SEEK_SET); fread(s, 1, writeLen, f); printf(s); delete s;}void main() {}
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 1610 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信