본문 바로가기
공부하며놀자/프로그래밍

파일 전체를 버퍼에 읽어오기

by 테너토너 2014. 10. 17.

http://stackoverflow.com/questions/18816126/c-read-the-whole-file-in-buffer



TCHAR szDirectory[MAX_PATH] = _T("");

::GetCurrentDirectory(sizeof(szDirectory) - 1, szDirectory); //Get Current Directory path

strPath.Format(_T("%s"), szDirectory); 

strPath.Append(_T("\\"));

strPath.Append(strFileName);

//strPath.Replace(_T("\\"),_T("\\\\"));


std::ifstream OpenedFile(strFileName, std::ios::binary);

OpenedFile.seekg(0, std::ios::end);

//std::streamsize dwResourceSize = OpenedFile.tellg();

OpenedFile.seekg(0, std::ios::beg);


std::string content((std::istreambuf_iterator<char>(OpenedFile)), std::istreambuf_iterator<char>());

std::streamsize dwResourceSize = content.size();


ULONG dwBytesWritten= NULL;

반응형

댓글