在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;
}

 

相关文章:

  • 2021-10-21
  • 2021-08-16
  • 2021-09-09
  • 2021-05-30
  • 2021-04-18
  • 2021-09-17
  • 2022-12-23
  • 2021-06-16
猜你喜欢
  • 2021-07-06
  • 2021-06-25
  • 2022-12-23
  • 2021-11-13
  • 2021-12-21
  • 2021-11-22
相关资源
相似解决方案