freopen

基本用法:freopen("文件名.拓展名","操作种类(我反正只知道有r&w)","标准输入输出");

    如果想重新用键盘屏幕输入输出,可以:freopen("CON","r或w","stdin或stdout");

几个简单的性质:

  1、stdin和stdout同时只能对应一个输入/输出的位置,即若freopen("test.in","r","stdin");后再写一条:freopen("data.in","r","stdin");那么test.in就会直接关闭,从data.in读取。同理stdout也一样。

   2、当使用freopen("xxx.xxx","w","stdout")时会先把xxx.xxx中的内容删除,应注意。 只有当stdout被成功关闭(fclose(stdout);或函数返回)是xxx.xxx才能保存输入的内容。(中途崩溃或调试时没有关闭就停止执行的话xxx.xxx的内容好像就会丢失的说)

   3、文件也可以是cpp或是exe类型的,不过只会把它当文本文件对待(不会运行的)

相关文章:

  • 2021-12-27
  • 2021-04-27
  • 2022-01-28
  • 2021-08-09
  • 2021-08-08
猜你喜欢
  • 2021-08-20
  • 2021-09-17
  • 2021-11-08
  • 2021-12-26
  • 2022-02-09
  • 2021-06-23
相关资源
相似解决方案