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<> 结构的文件