fwrite函数在vs2015和vs2012中的区别

时间:2017-08-23 03:56:00

标签: c++

当我在调用fwrite()后调用fclose()时,vs2012没有抛出错误,但在VS 2015中它会抛出错误。

The error information capture in vs2015

代码如下:

int main()
{
    FILE* m_pFile;
    char* filePath = "D:\\test_vs2015.txt";
    fopen_s(&m_pFile, filePath, "w+");
    if (m_pFile == NULL)
        return 0;
    char* str = "strNum text";
    int flag = 0;
    while (str[flag++] != '\0');
    int num = fwrite(str, 1, flag - 1, m_pFile);
    int fcloseFlag = fclose(m_pFile);
    if (m_pFile == NULL)
        printf("m_pFile == NULL ");
    else
        printf("m_pFile != NULL ");
    int writeNum = fwrite(str, 1, flag - 1, m_pFile);
    return 0;
}

1 个答案:

答案 0 :(得分:-2)

文件关闭函数不以整数形式返回,而是使用bool。