Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void load::fileToString(const char *filename, std::string *load)
- {
- clock_t time_a = clock();
- std::ifstream fst(filename);
- if(fst.is_open())
- {
- std::string str;
- fst.seekg(0, std::ios::end);
- str.reserve(fst.tellg());
- fst.seekg(0, std::ios::beg);
- str.assign((std::istreambuf_iterator<char>(fst)), std::istreambuf_iterator<char>());
- *load = str;
- std::string().swap(str);
- clock_t time_b = clock();
- int elapsed = time_b - time_a;
- std::stringstream ss;
- ss << elapsed;
- std::string elapsedStr = ss.str();
- std::cout << "Successfully loaded " << filename << " in " << elapsedStr << " seconds." << std::endl;
- std::string().swap(elapsedStr);
- }
- else
- {
- std::cout << "Failed to load " << filename << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement