size_t GetFileSize(FILE* file) {
fseek(file, , SEEK_END);
return static_cast<size_t>(ftell(file));
} std::string ReadEntireFile(FILE* file) {
const size_t file_size = GetFileSize(file);
char* const buffer = new char[file_size]; size_t bytes_last_read = ; // # of bytes read in the last fread()
size_t bytes_read = ; // # of bytes read so far fseek(file, , SEEK_SET); // Keeps reading the file until we cannot read further or the
// pre-determined file size is reached.
do {
bytes_last_read = fread(buffer+bytes_read, , file_size-bytes_read, file);
bytes_read += bytes_last_read;
} while (bytes_last_read > && bytes_read < file_size); const std::string content(buffer, bytes_read);
delete[] buffer; return content;
}

最新文章

  1. Warning: file_put_contents(data.txt): failed to open stream: Permission denied in /Library/WebServer/Documents/test.php on line 22
  2. Cross join in excel --- Copy from Internet
  3. C++11引用临时变量的终极解析
  4. 【代码笔记】iOS-点击任何处,出现城市
  5. iOS开发之静态库(四)—— 静态框架framework制作
  6. Function Scope
  7. 【转】Eclipse去除js(JavaScript)验证错误
  8. MongoDB工具MagicMongoDBTool
  9. 【3D研发笔记】之【数学相关】(一):坐标系
  10. 学习C++ Primer 的个人理解(三)
  11. javascript 中的location.reload
  12. Example005控制弹出窗口居中显示
  13. 201521123079《java程序设计》第7周学习总结
  14. windows 环境安装oracle11g db 或者RAC 防火墙必需要透过的进程,port
  15. Spring Boot 2.X 如何优雅的解决跨域问题?
  16. ASCLL、Unicode和UTF-8编码的理解
  17. Java的Spring内实现的mini版内存&quot;计数器&quot;功能
  18. 关于给C盘扩容以及动态磁盘
  19. .net core 生成二维码
  20. NO.6LINUX基本命令

热门文章

  1. JAVA 定时器的三种方法
  2. Linux的kickstart安装详解
  3. list count++
  4. [C++] Pure Virtual Function and Abstract Class
  5. [SoapUI] Context is per test case, every test case has a different context
  6. Flask框架 之 信号
  7. Java Persistence with MyBatis 3(中文版) 第二章 引导MyBatis
  8. java中List的用法和实例详解
  9. PM2部署资料
  10. LightOJ 1268 Unlucky Strings (KMP+矩阵快速幂)