Created
January 28, 2014 19:00
-
-
Save Naltharial/8673915 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int fileToString(const char *filename, std::string& s) | |
{ | |
size_t size; | |
char* str; | |
std::fstream f(filename, (std::fstream::in | std::fstream::binary)); | |
if (f.is_open()) | |
{ | |
size_t fileSize; | |
f.seekg(0, std::fstream::end); | |
size = fileSize = (size_t)f.tellg(); | |
f.seekg(0, std::fstream::beg); | |
str = new char[size + 1]; | |
if (!str) | |
{ | |
f.close(); | |
return SDK_SUCCESS; | |
} | |
f.read(str, fileSize); | |
f.close(); | |
str[size] = '\0'; | |
s = str; | |
delete[] str; | |
return SDK_SUCCESS; | |
} | |
std::cout << "Error: failed to open file\n:" << filename << std::endl; | |
return SDK_FAILURE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment