码迷,mamicode.com
首页 > 其他好文 > 详细

VS2015 中使用freopen_s

时间:2017-05-31 20:10:20      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:使用方法   ios   vs2015   printf   return   int   span   fopen   pre   

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

 

VS2015 中使用freopen_s

标签:使用方法   ios   vs2015   printf   return   int   span   fopen   pre   

原文地址:http://www.cnblogs.com/Vincent-Bryan/p/6925639.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!