VS2015 中使用freopen_s


在VS2015中直接使用freopen會報錯,系統提示使用函數freopen_s作為代替,其使用方法如下:

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;



int main(){
    FILE *stream1, *stream2;
    fopen_s(&stream1, "input.txt", "r"); 
    fopen_s(&stream2, "output.txt", "w");

    int n;
    fscanf_s(stream1, "%d", &n);//從stream1中讀取一個int
    fprintf(stream2, "%d", n);  //將int輸出到stream2

    fclose(stream1);
    fclose(stream2);
    return 0;
}

 


免責聲明!

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



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