在最新的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 這么寫就找不到文件