Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. void load::fileToString(const char *filename, std::string *load)
  2. {
  3. clock_t time_a = clock();
  4. std::ifstream fst(filename);
  5. if(fst.is_open())
  6. {
  7. std::string str;
  8. fst.seekg(0, std::ios::end);
  9. str.reserve(fst.tellg());
  10. fst.seekg(0, std::ios::beg);
  11.  
  12. str.assign((std::istreambuf_iterator<char>(fst)), std::istreambuf_iterator<char>());
  13.  
  14. *load = str;
  15. std::string().swap(str);
  16.  
  17. clock_t time_b = clock();
  18. int elapsed = time_b - time_a;
  19. std::stringstream ss;
  20. ss << elapsed;
  21. std::string elapsedStr = ss.str();
  22. std::cout << "Successfully loaded " << filename << " in " << elapsedStr << " seconds." << std::endl;
  23. std::string().swap(elapsedStr);
  24. }
  25. else
  26. {
  27. std::cout << "Failed to load " << filename << std::endl;
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement