码迷,mamicode.com
首页 > 编程语言 > 详细

C++实现根据路径读取文件内容

时间:2018-12-12 23:41:20      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:c++   fst   div   temp   代码   ==   tor   pos   内容   

已知文件路径,用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;
}

 

C++实现根据路径读取文件内容

标签:c++   fst   div   temp   代码   ==   tor   pos   内容   

原文地址:https://www.cnblogs.com/calence/p/10111523.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!