zoukankan      html  css  js  c++  java
  • vector 的读写

    void CPreData::ReadDataWarehouse()
    {
    	UINT nVectorSize = 0;
    	HANDLE hFile = CreateFile(m_szDataWarehouse, FILE_READ_DATA, FILE_SHARE_READ,
            NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    
    	if (INVALID_HANDLE_VALUE == hFile)
            return;
    
    	DWORD dwRead = 0;
    	ReadFile(hFile, &nVectorSize, sizeof(UINT), &dwRead, 0);
    	m_vDataWarehouse.resize(nVectorSize);
    	SetFilePointer(hFile, sizeof(UINT), 0, FILE_BEGIN);
    	ReadFile(hFile, &m_vDataWarehouse[0], nVectorSize * sizeof(INIFILE), &dwRead, 0);
    	
    	CloseHandle(hFile);
    
    	for(vector<INIFILE>::iterator iter = m_vDataWarehouse.begin(); iter != m_vDataWarehouse.end(); ++iter)
    		iter->Inverse();
    }
    void CPreData::WriteDataWarehouse()
    {
    	for(vector<INIFILE>::iterator iter = m_vDataWarehouse.begin(); iter != m_vDataWarehouse.end(); ++iter)
    		iter->Inverse();
    
    	HANDLE hFile = CreateFile(m_szDataWarehouse, FILE_WRITE_DATA, FILE_SHARE_READ,
            NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    
        if (INVALID_HANDLE_VALUE == hFile)
    		return;
    
    	UINT nVectorSize = m_vDataWarehouse.size();
    	DWORD dwWrite = 0;
    	WriteFile(hFile, &nVectorSize, sizeof(UINT), &dwWrite, 0);
    	SetFilePointer(hFile, sizeof(UINT), 0, FILE_BEGIN);
    	WriteFile(hFile, &m_vDataWarehouse[0], nVectorSize * sizeof(INIFILE), &dwWrite, 0);
        CloseHandle(hFile);
    }

    如何读写 vector<> 结构的文件
  • 相关阅读:
    Vue基本使用
    缓存数据库
    Web框架
    爬虫基础知识及scrapy框架使用和基本原理
    轮播组件/瀑布流/组合搜索/KindEditor插件
    Model&Form&ModelForm拾遗
    评论操作展示
    评论操作
    windows 下安装 redis
    Notepad++ 列块模式编辑,替换换行符
  • 原文地址:https://www.cnblogs.com/silyvin/p/9106901.html
Copyright © 2011-2022 走看看