已知文件路径,用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; }
原文:https://www.cnblogs.com/calence/p/10111523.html