当前位置: 首页>>代码示例>>C++>>正文


C++ cString::c_str方法代码示例

本文整理汇总了C++中cString::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ cString::c_str方法的具体用法?C++ cString::c_str怎么用?C++ cString::c_str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cString的用法示例。


在下文中一共展示了cString::c_str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DoesDirectoryExist

// Verifies that directory exists.
// Returns success if the directory exists and is readable (failure may mean
// it's busy or permissions denied on win32)
//-----------------------------------------------------------------------------
CPUTResult CPUTFileSystem::DoesDirectoryExist(const cString &path)
{
#ifdef CPUT_OS_ANDROID
    // On Android, all files are in the APK and are compressed.
    // We do not have access to the standard file system, so
    // all files need streaming from memory through the android asset manager
    AAssetManager* assetManager = CPUTWindowAndroid::GetAppState()->activity->assetManager;
    
    AAssetDir* AssetDir = AAssetManager_openDir(assetManager, path.c_str());
    if (AssetDir)
        return CPUT_SUCCESS;
#else
    struct stat fileAttributes;
    
    int result = stat(path.c_str(), &fileAttributes);
    if (result == -1) {
        DEBUG_ERROR(strerror(errno));
        result = CPUT_ERROR; 
    }
	
    if (S_ISDIR(fileAttributes.st_mode)) {
        return CPUT_SUCCESS;
    }
#endif
    return CPUT_ERROR;
}
开发者ID:Cristianohh,项目名称:InstancingAndroid,代码行数:30,代码来源:CPUTOSServicesLinux.cpp

示例2: ReadFileContents

// Read the entire contents of a file and return a pointer/size to it
//-----------------------------------------------------------------------------
CPUTResult CPUTFileSystem::ReadFileContents(const cString &fileName, UINT *pSizeInBytes, void **ppData, bool bAddTerminator, bool bLoadAsBinary)
{
    FILE *pFile = NULL;

    errno_t err;
    if (bLoadAsBinary) {
#if defined (UNICODE) || defined(_UNICODE)
        err = _wfopen_s(&pFile, fileName.c_str(), _L("rb"));
#else
        err = fopen_s(&pFile, fileName.c_str(), "rb");
#endif
    } else {
#if defined (UNICODE) || defined(_UNICODE)
        err = _wfopen_s(&pFile, fileName.c_str(), _L("r"));
#else
        err = fopen_s(&pFile, fileName.c_str(), "r");
#endif
    }

    if(0 == err)
    {
        // get file size
        fseek(pFile, 0, SEEK_END);
        *pSizeInBytes = ftell(pFile);
        fseek (pFile, 0, SEEK_SET);

        // allocate buffer
        *ppData = (void*) new char[*pSizeInBytes];
        ASSERT( *ppData, _L("Out of memory") );

        // read it all in
        UINT numBytesRead = (UINT) fread(*ppData, sizeof(char), *pSizeInBytes, pFile);
        if (bAddTerminator)
        {
            ((char *)(*ppData))[numBytesRead++] = '\0';
            (*pSizeInBytes)++;
        }
        //fixme - this isn't doing what it appears to be doing. counts off for Windows...
        //ASSERT( numBytesRead == *pSizeInBytes, _L("File read byte count mismatch.") );
        UNREFERENCED_PARAMETER(numBytesRead);

        // close and return
        fclose(pFile);
        return CPUT_SUCCESS;
    }

    // some kind of file error, translate the error code and return it
    return TranslateFileError(err);
}
开发者ID:Cristianohh,项目名称:InstancingAndroid,代码行数:51,代码来源:CPUTOSServicesWin.cpp

示例3: CPUTSetDebugName

//-----------------------------------------------------------------------------
CPUTResult CPUTTextureDX11::CreateNativeTexture(
    ID3D11Device *pD3dDevice,
    const cString &fileName,
    ID3D11ShaderResourceView **ppShaderResourceView,
    ID3D11Resource **ppTexture,
    bool ForceLoadAsSRGB)
{
    HRESULT hr;

    hr = DirectX::CreateDDSTextureFromFileEx(
        pD3dDevice,
        fileName.c_str(),
        0,//maxsize
        D3D11_USAGE_DEFAULT,
        D3D11_BIND_SHADER_RESOURCE,
        0,
        0,
        ForceLoadAsSRGB,
        ppTexture,
        ppShaderResourceView);
	if( FAILED( hr ) )
	{
		ASSERT( false, _L("Failed to load texture: ") + fileName )
		return CPUT_TEXTURE_LOAD_ERROR;
	}

    CPUTSetDebugName( *ppTexture, fileName );
    CPUTSetDebugName( *ppShaderResourceView, fileName );

    return CPUT_SUCCESS;
}
开发者ID:GameTechDev,项目名称:OpenGLESTessellation,代码行数:32,代码来源:CPUTTextureDX11.cpp

示例4: iCPUTifstream

CPUTFileSystem::CPUTandroidifstream::CPUTandroidifstream(const cString &fileName, std::ios_base::openmode mode) : iCPUTifstream(fileName, mode)
{
    mpAsset = NULL;
    mpAssetDir = NULL;
    mbEOF = true;
    
    // Extract the file and dir
    int length = fileName.length();
    int index = fileName.find_last_of("\\/");
    cString file = fileName.substr(index + 1, (length - 1 - index));
    cString dir  = fileName.substr(0, index);
    
    // On Android, all files are in the APK and are compressed.
    // We do not have access to the standard file system, so
    // all files need streaming from memory through the android asset manager
    AAssetManager* assetManager = CPUTWindowAndroid::GetAppState()->activity->assetManager;
    
    mpAssetDir = AAssetManager_openDir(assetManager, dir.c_str());
    if (!mpAssetDir)
        DEBUG_PRINT("Failed to load asset Dir");
    
    const char* assetFileName = NULL;
    while ((assetFileName = AAssetDir_getNextFileName(mpAssetDir)) != NULL) 
    {
        if (strcmp(file.c_str(), assetFileName) == 0)
        {
            // For some reason we need to pass in the fully pathed filename here, rather than the relative filename
            // that we have just been given. This feels like a bug in Android!
            mpAsset = AAssetManager_open(assetManager, fileName.c_str()/*assetFileName*/, AASSET_MODE_STREAMING);
            if (mpAsset)
                mbEOF = false;
            return;
        }
    }
}
开发者ID:Cristianohh,项目名称:InstancingAndroid,代码行数:35,代码来源:CPUTOSServicesLinux.cpp

示例5: ASSERT

// Use DX11 compile from file method to do all the heavy lifting
//-----------------------------------------------------------------------------
CPUTResult CPUTAssetLibraryDX11::CompileShaderFromMemory(
    const char     *pShaderSource,
    const cString  &shaderMain,
    const cString  &shaderProfile,
    ID3DBlob      **ppBlob
)
{
    CPUTResult result = CPUT_SUCCESS;

    char pShaderMainAsChar[128];
    char pShaderProfileAsChar[128];
    ASSERT( shaderMain.length()     < 128, _L("Shader main name '")    + shaderMain    + _L("' longer than 128 chars.") );
    ASSERT( shaderProfile.length()  < 128, _L("Shader profile name '") + shaderProfile + _L("' longer than 128 chars.") );
    size_t count;
    wcstombs_s( &count, pShaderMainAsChar,    shaderMain.c_str(),    128 );
    wcstombs_s( &count, pShaderProfileAsChar, shaderProfile.c_str(), 128 );

    // use DirectX to compile the shader file
    ID3DBlob *pErrorBlob = NULL;
    D3D10_SHADER_MACRO pShaderMacros[2] = { "_CPUT", "1", NULL, NULL }; // TODO: Support passed-in, and defined in .mtl file.  Perhaps under [Shader Defines], etc
    char *pShaderMainAsChars = ws2s(shaderMain.c_str());
    HRESULT hr = D3DX11CompileFromMemory(
        pShaderSource,     // shader as a string
        strlen( pShaderSource ), //
        pShaderMainAsChars, // Use entrypoint as file name
        pShaderMacros,        // macro define's
        NULL,                 // includes
        pShaderMainAsChar,    // main function name
        pShaderProfileAsChar, // shader profile/feature level
        0,                    // flags 1
        0,                    // flags 2
        NULL,                 // threaded load? (no for right now)
        ppBlob,               // blob data with compiled code
        &pErrorBlob,          // any compile errors stored here
        NULL
    );
    ASSERT( SUCCEEDED(hr), _L("Error compiling shader '") + shaderMain + _L("'.\n") + (pErrorBlob ? s2ws((char*)pErrorBlob->GetBufferPointer()) : _L("no error message") ) );
    if(pErrorBlob)
    {
        pErrorBlob->Release();
    }
    delete pShaderMainAsChars;
    return result;
}
开发者ID:GameTechDev,项目名称:OutdoorLightScattering,代码行数:46,代码来源:CPUTAssetLibraryDX11.cpp

示例6: MapKey

CPUTKey MapKey(cString strKey)
{
    for(int i = 0; i < KEY_NUM_KEYS; i++)
    {
        if( 0 == strKey.compare(CPUTKeyMap[i].name))
            return CPUTKeyMap[i].value;
    }
    DEBUG_PRINT(_L("Unknown Key: %s"), strKey.c_str());
    return KEY_NUM_KEYS;
}
开发者ID:swq0553,项目名称:ClusteredShadingAndroid,代码行数:10,代码来源:CPUTGUIElement.cpp

示例7: OpenFile

// Open a file and return file pointer to it
//-----------------------------------------------------------------------------
CPUTResult CPUTFileSystem::OpenFile(const cString &fileName, FILE **ppFilePointer)
{
#ifdef CPUT_OS_ANDROID
    DEBUG_PRINT("OpenFile stubbed");
#else
    *ppFilePointer = fopen(fileName.c_str(), "r");
    
    if (*ppFilePointer == NULL) {
        return CPUT_ERROR;
    }
#endif    
    return CPUT_SUCCESS;
}
开发者ID:Cristianohh,项目名称:InstancingAndroid,代码行数:15,代码来源:CPUTOSServicesLinux.cpp

示例8: SetText

void CPUTGUIElement::SetText(cString string)
{
    DEBUG_PRINT(_L("GUIElement SetText: %s"), string.c_str());
    mText = string;
    if(mpFont && mpTextMaterial)
    {
        DEBUG_PRINT(_L("\t have font and material"));
        if(!mpTextMesh)
        {
#ifdef CPUT_FOR_DX11
            mpTextMesh = new CPUTMeshDX11();
#else
            mpTextMesh = new CPUTMeshOGL();
#endif
        }
        unsigned int numCharacters = (unsigned int) string.size();
        unsigned int numVertices = numCharacters * 6;
        CPUTGUIVertex* pVB = new CPUTGUIVertex[numVertices];

        CPUTBufferElementInfo pGUIVertex[3] = {
            { "POSITION", 0, 0, CPUT_F32, 3, 3*sizeof(float), 0 },            
            { "TEXCOORD", 0, 1, CPUT_F32, 2, 2*sizeof(float), 3*sizeof(float)},
            { "COLOR",    0, 2, CPUT_F32, 4, 4*sizeof(float), 5*sizeof(float)},
        };
        mpFont->LayoutText(NULL, &mTextWidth, &mTextHeight, mText, 0, 0);
        mTextX = (mWidth-mTextWidth)/2;
        mTextY = (mHeight-mTextHeight)/2;
        mpFont->LayoutText(pVB, &mTextWidth, &mTextHeight, mText, 0, 0);
        mpTextMesh->CreateNativeResources(NULL, 1, 3, pGUIVertex, numVertices, pVB, NULL, 0, NULL);
        
#ifdef CPUT_FOR_DX11
        mpTextMesh->SetMeshTopology(CPUT_TOPOLOGY_INDEXED_TRIANGLE_LIST);
        
        D3D11_INPUT_ELEMENT_DESC layout[] =
        {
            { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },            
            { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
            { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 },
        };
        UINT numElements = ARRAYSIZE( layout );
        ID3DBlob* pBlob = ((CPUTMaterialEffectDX11*)mpTextMaterial->GetMaterialEffects()[0])->GetVertexShader()->GetBlob();
        
        CPUT_DX11::GetDevice()->CreateInputLayout( layout, numElements, pBlob->GetBufferPointer(), pBlob->GetBufferSize(), &mpVertexLayout );
        CPUTSetDebugName( mpVertexLayout, "CPUT GUI InputLayout object");
#else
#endif
        SAFE_DELETE_ARRAY(pVB);
    }
}
开发者ID:swq0553,项目名称:ClusteredShadingAndroid,代码行数:49,代码来源:CPUTGUIElement.cpp

示例9: GetEventValue

int GetEventValue(StringMap eventMap[], cString event)
{
    int i = 0; 
    while(eventMap[i].value > 0)
    {
        if(event.compare(eventMap[i].key) == 0)
        {
            DEBUG_PRINT(_L("Found Event: %s\n"), event.c_str());
            return eventMap[i].value;

        }
        i++;
    }
    return -1;
}
开发者ID:swq0553,项目名称:ClusteredShadingAndroid,代码行数:15,代码来源:CPUTGUIElement.cpp

示例10: CPUTSetDebugName

//-----------------------------------------------------------------------------
void CPUTSetDebugName( void *pResource, cString name )
{
#ifdef _DEBUG
    char pCharString[CPUT_MAX_STRING_LENGTH];
    const wchar_t *pWideString = name.c_str();
    UINT ii;
    UINT length = min( (UINT)name.length(), (CPUT_MAX_STRING_LENGTH-1));
    for(ii=0; ii<length; ii++)
    {
        pCharString[ii] = (char)pWideString[ii];
    }
    pCharString[ii] = 0; // Force NULL termination
    ((ID3D11DeviceChild*)pResource)->SetPrivateData( WKPDID_D3DDebugObjectName, (UINT)name.length(), pCharString );
#endif // _DEBUG
}
开发者ID:galek,项目名称:SoftOcclude,代码行数:16,代码来源:CPUT_DX11.cpp

示例11: DoesFileExist

// Verifies that file exists at specified path
// // #### this should probably just return a bool
//-----------------------------------------------------------------------------
CPUTResult CPUTFileSystem::DoesFileExist(const cString &pathAndFilename)
{
#ifdef CPUT_OS_ANDROID
    DEBUG_PRINT("DoesFileExist stubbed");
#else
    struct stat fileAttributes;
    
    int result = stat(pathAndFilename.c_str(), &fileAttributes);
    if (result == -1) {
        DEBUG_ERROR(strerror(errno));
        result = CPUT_ERROR; 
    }
	
    if (S_ISREG(fileAttributes.st_mode)) {
        return CPUT_SUCCESS;
    }
#endif    
    return CPUT_ERROR;
}
开发者ID:Cristianohh,项目名称:InstancingAndroid,代码行数:22,代码来源:CPUTOSServicesLinux.cpp

示例12: ResolveAbsolutePathAndFilename

// Takes a relative/full path+fileName and returns the absolute path with drive
// letter, absolute path, fileName and extension of this file.
// Truncates total path/file length to CPUT_MAX_PATH
//-----------------------------------------------------------------------------
CPUTResult CPUTFileSystem::ResolveAbsolutePathAndFilename(const cString &fileName, cString *pResolvedPathAndFilename)
{
    CPUTResult  result   = CPUT_SUCCESS;
#ifdef CPUT_OS_ANDROID
    pResolvedPathAndFilename->assign(fileName);
#else
    char       *fullPath = NULL;

    fullPath = realpath(fileName.c_str(), NULL);
    if (fullPath == NULL) {
        DEBUG_ERROR(fileName);
        DEBUG_ERROR(strerror(errno));
        result = CPUT_ERROR;
        return result;
    }
    
    pResolvedPathAndFilename->assign(fullPath);
    
    free(fullPath); // realpath() mallocs the memory required to hold the path name, so we need to free it
#endif
    return result;
}
开发者ID:Cristianohh,项目名称:InstancingAndroid,代码行数:26,代码来源:CPUTOSServicesLinux.cpp

示例13:

// Pop up a message box with specified title/text
//-----------------------------------------------------------------------------
void CPUT_DX11::CPUTMessageBox(const cString DialogBoxTitle, const cString DialogMessage)
{
    CPUTOSServices::GetOSServices()->OpenMessageBox(DialogBoxTitle.c_str(), DialogMessage.c_str());
}
开发者ID:galek,项目名称:SoftOcclude,代码行数:6,代码来源:CPUT_DX11.cpp

示例14: LoadModelPayload

//-----------------------------------------------------------------------------
CPUTResult CPUTModel::LoadModelPayload(const cString &File)
{
    CPUTResult result = CPUT_SUCCESS;

    std::ifstream file(File.c_str(), std::ios::in | std::ios::binary);
    ASSERT( !file.fail(), _L("CPUTModelDX11::LoadModelPayload() - Could not find binary model file: ") + File );

    // set up for mesh creation loop
    UINT meshIndex = 0;
    while(file.good() && !file.eof())
    {
        // TODO: rearrange while() to avoid if(eof).  Should perform only one branch per loop iteration, not two
        CPUTRawMeshData vertexFormatDesc;
        vertexFormatDesc.Read(file);
        if(file.eof())
        {
            // TODO:  Wtf?  Why would we get here?  We check eof at the top of loop.  If it isn't eof there, why is it eof here?
            break;
        }
        ASSERT( meshIndex < mMeshCount, _L("Actual mesh count doesn't match stated mesh count"));

        // create the mesh.
        CPUTMesh *pMesh = mpMesh[meshIndex];

        // always a triangle list (at this point)
        pMesh->SetMeshTopology(CPUT_TOPOLOGY_INDEXED_TRIANGLE_LIST);

        // get number of data blocks in the vertex element (pos,norm,uv,etc)
        // YUCK! TODO: Use fixed-size array of elements
        CPUTBufferInfo *pVertexElementInfo = new CPUTBufferInfo[vertexFormatDesc.mFormatDescriptorCount];
        // pMesh->SetBounds(vertexFormatDesc.mBboxCenter, vertexFormatDesc.mBboxHalf);

        // running count of each type of  element
        int positionStreamCount=0;
        int normalStreamCount=0;
        int texCoordStreamCount=0;
        int tangentStreamCount=0;
        int binormalStreamCount=0;
        int colorStreamCount=0;

        int RunningOffset = 0;
        for(UINT ii=0; ii<vertexFormatDesc.mFormatDescriptorCount; ii++)
        {
            // lookup the CPUT data type equivalent
            pVertexElementInfo[ii].mElementType = CPUT_FILE_ELEMENT_TYPE_TO_CPUT_TYPE_CONVERT[vertexFormatDesc.mpElements[ii].mVertexElementType];
            ASSERT((pVertexElementInfo[ii].mElementType !=CPUT_UNKNOWN ) , _L(".MDL file load error.  This model file has an unknown data type in it's model data."));
            // calculate the number of elements in this stream block (i.e. F32F32F32 = 3xF32)
            pVertexElementInfo[ii].mElementComponentCount = vertexFormatDesc.mpElements[ii].mElementSizeInBytes/CPUT_DATA_FORMAT_SIZE[pVertexElementInfo[ii].mElementType];
            // store the size of each element type in bytes (i.e. 3xF32, each element = F32 = 4 bytes)
            pVertexElementInfo[ii].mElementSizeInBytes = vertexFormatDesc.mpElements[ii].mElementSizeInBytes;
            // store the number of elements (i.e. 3xF32, 3 elements)
            pVertexElementInfo[ii].mElementCount = vertexFormatDesc.mVertexCount;
            // calculate the offset from the first element of the stream - assumes all blocks appear in the vertex stream as the order that appears here
            pVertexElementInfo[ii].mOffset = RunningOffset;
            RunningOffset = RunningOffset + pVertexElementInfo[ii].mElementSizeInBytes;

            // extract the name of stream
            pVertexElementInfo[ii].mpSemanticName = CPUT_VERTEX_ELEMENT_SEMANTIC_AS_STRING[ii];

            switch(vertexFormatDesc.mpElements[ii].mVertexElementSemantic)
            {
            case CPUT_VERTEX_ELEMENT_POSITON:
                pVertexElementInfo[ii].mpSemanticName = "POSITION";
                pVertexElementInfo[ii].mSemanticIndex = positionStreamCount++;
                break;
            case CPUT_VERTEX_ELEMENT_NORMAL:
                pVertexElementInfo[ii].mpSemanticName = "NORMAL";
                pVertexElementInfo[ii].mSemanticIndex = normalStreamCount++;
                break;
            case CPUT_VERTEX_ELEMENT_TEXTURECOORD:
                pVertexElementInfo[ii].mpSemanticName = "TEXCOORD";
                pVertexElementInfo[ii].mSemanticIndex = texCoordStreamCount++;
                break;
            case CPUT_VERTEX_ELEMENT_TANGENT:
                pVertexElementInfo[ii].mpSemanticName = "TANGENT";
                pVertexElementInfo[ii].mSemanticIndex = tangentStreamCount++;
                break;
            case CPUT_VERTEX_ELEMENT_BINORMAL:
                pVertexElementInfo[ii].mpSemanticName = "BINORMAL";
                pVertexElementInfo[ii].mSemanticIndex = binormalStreamCount++;
                break;
            case CPUT_VERTEX_ELEMENT_VERTEXCOLOR:
                pVertexElementInfo[ii].mpSemanticName = "COLOR";
                pVertexElementInfo[ii].mSemanticIndex = colorStreamCount++;
                break;
            default:
                cString errorString = _L("Invalid vertex semantic in: '")+File+_L("'\n");
                TRACE(errorString.c_str());
                ASSERT(0, errorString);
            }
        }

        // Index buffer
        CPUTBufferInfo indexDataInfo;
        indexDataInfo.mElementType           = (vertexFormatDesc.mIndexType == tUINT32) ? CPUT_U32 : CPUT_U16;
        indexDataInfo.mElementComponentCount = 1;
        indexDataInfo.mElementSizeInBytes    = (vertexFormatDesc.mIndexType == tUINT32) ? sizeof(UINT32) : sizeof(UINT16);
        indexDataInfo.mElementCount          = vertexFormatDesc.mIndexCount;
        indexDataInfo.mOffset                = 0;
//.........这里部分代码省略.........
开发者ID:galek,项目名称:SoftOcclude,代码行数:101,代码来源:CPUTModel.cpp

示例15: LoadShaderFileString

// load a file and return it's contents
//-----------------------------------------------------------------------------
CPUTResult CPUTAssetLibraryOGLES::LoadShaderFileString(const cString Filename, void** ppData)
{
    if(NULL == ppData)
    {
        ASSERT( ppData, _L("Invalid data pointer for storing shader string"));
        return CPUT_ERROR_INVALID_PARAMETER;
    }

    FILE* pFile = NULL;
#if defined (UNICODE) || defined(_UNICODE)
    errno_t err = _wfopen_s(&pFile, Filename.c_str(), _L("r"));
#else
    errno_t err = fopen_s(&pFile, Filename.c_str(), _L("r"));
#endif
    ASSERT( (0 == err), _L("Error loading shader file: ")+Filename);
    if(0 != err)
    {
        // error opening file
        //        char message[250];
        //        sprintf_s(message, 250, "Could not find file: %s\n", filename);
        //        MessageBox("Error: Load file", message, CPUT_MB_ERROR);

        return CPUT_ERROR_FILE_NOT_FOUND;
    }


    // file open - read contents
    // get file size
    err = fseek( pFile, 0, SEEK_END );
    ASSERT( (0 == err), _L("Error reading contents of shader file: ")+Filename);
    if(0!=err)
    {
        //        char message[250];
        //        sprintf_s(message, 250, "Error getting file size: %s\n", filename);
        //        MessageBox("Error: Load file", message, CPUT_MB_ERROR);
        fclose(pFile);
        return CPUT_ERROR_FILE_READ_ERROR;
    }

    long endPos = ftell( pFile );

    fseek( pFile, 0, SEEK_SET );
    ASSERT( (0 == err), _L("Error getting size of shader file: ")+Filename);
    if(0!=err)
    {
        //        char message[250];
        //        sprintf_s(message, 250, "Error getting file size: %s\n", filename);
        //        MessageBox("Error: Load file", message, CPUT_MB_ERROR);
        fclose(pFile);
        return CPUT_ERROR_FILE_READ_ERROR;
    }

    // allocate buffer
    char* pContents = new char[endPos+1];

    // read the contents!
    size_t actuallyRead = fread(pContents, sizeof(char), endPos, pFile);
    pContents[actuallyRead] = '\0'; // always null terminate on your own - not guaranteed by fread()

    // close file
    err = fclose(pFile);
    ASSERT( (0 == err), _L("Error closing shader file: ")+Filename);

    
    if(pFile)
    {   
        if(0 != err)
        {
            // file did not close properly!
            //           char message[250];
            //           sprintf_s(message, 250, "File did not close properly: %s\n", filename);
            //           MessageBox("Error: Load file", message, CPUT_MB_ERROR);
            delete [] pContents;
            return CPUT_ERROR_FILE_CLOSE_ERROR;
        }
    }

    // set the return buffer
    *ppData = pContents;

    return CPUT_SUCCESS;
}
开发者ID:Habaut,项目名称:intel_occlusion_cull,代码行数:84,代码来源:CPUTAssetLibraryOGLES.cpp


注:本文中的cString::c_str方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。