關於 fopen_s的用法


在最新的vs中已經不能使用 fopen 必須使用 fopen_s函數

基本的使用方法是

#include<stdio.h>

int main()
{
    FILE* fp;
    // errno_t == int ,也就是 typedef int errn_t
    errno_t error;
    error = fopen_s(&fp, "C:\\users\\mike1\\desktop\\mm.txt", "w+");
    //這里的返回值是,如果成功返回0,如果不成功返回非0
    if (error != 0 )
    {
        printf("打開失敗");
    }

    char name[] = "你好,師姐。";
    fwrite(name, 1, sizeof(name), fp);
    fclose(fp);
    return 0;
}

不知為什么  C:\\mm.txt  這么寫就找不到文件

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM