C++判断一个文件是否可以正确打开的代码

 

/* fopen example */
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    FILE* fp;
    fp = fopen("C:/Users/Qin/Desktop/123.txt", "rb");
    if ((fp == NULL))
    {
        printf("\nerror on open C:/Users/Qin/Desktop/123.txt!");
        _getch();
        exit(1);
    }
    else
    {
        cout<<"the file C:/Users/Qin/Desktop/123.txt can be open correctly!" << endl;
    }
    system("pause");
    return 0;
}

 

posted on 2019-01-21 10:25  一杯明月  阅读(2785)  评论(0编辑  收藏  举报