Open file by its full path in C++

前端 未结 5 2308
暖寄归人
暖寄归人 2021-02-18 21:24

I want the user to give me the full path where the file exists and not just the file name. How do I open the file this way?

Is it something like this:

if         


        
5条回答
  •  野性不改
    2021-02-18 22:05

    The code seems working to me. I think the same with @Iothar.

    Check to see if you include the required headers, to compile. If it is compiled, check to see if there is such a file, and everything, names etc, matches, and also check to see that you have a right to read the file.

    To make a cross check, check if you can open it with fopen..

    FILE *f = fopen("C:/Demo.txt", "r");
    if (f)
      printf("fopen success\n");
    

提交回复
热议问题