C++实现根据路径读取文件内容
已知文件路径,用C++实现读取对应文件的内容,代码如下:
bool LoadShaderStr(const char* szShaderPath,string& strShaderStr) { if(NULL == szShaderPath) return false; std::ifstream iShaderStram(szShaderPath,std::ios::in); if(iShaderStram.is_open()) { std::stringstream strTemp; strTemp<<iShaderStram.rdbuf(); strShaderStr = strTemp.str(); iShaderStram.close(); return true; } printf("Impossible to open %s. Are you in the right directory ? Don't forget to read the FAQ !\n", szShaderPath); getchar(); return false; }