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;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM