2019/01
-
c++, istream으로 읽은 개수 반환 gcount프로그래밍/코드 조각 2019. 1. 19. 12:21
readsome이 아니다. auto MakeHash(std::istream& is){ std::array fileHash; SHA256_CTX ctx; SHA256_Init(&ctx); char buf[512]{ 0, }; while (is.good()) { is.read(buf, sizeof(buf)); const int cnt = is.gcount(); SHA256_Update(&ctx, buf, cnt); } SHA256_Final(fileHash.data(), &ctx); return fileHash;}gcount는 마지막으로 읽어난 엘리먼트의 개수를 반환한다.
-