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

 

posted @ 2018-12-12 22:43  bky2016  阅读(2477)  评论(0编辑  收藏  举报