1. 程式人生 > >C++實現根據路徑讀取檔案內容

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