【发布时间】:2018-03-12 06:31:33
【问题描述】:
我试图从 vs17 中的文件中读取。但是这里 system("pause") 不起作用。这里的控制台窗口只是弹出并消失。 input.txt 文件只包含一个整数。
#include<iostream>
#include<stdio.h>
#include<cstdio>
#pragma warning(disable:4996)
using namespace std;
int main()
{
freopen("input.txt", "r", stdin);
int n;
cin >> n;
cout << n << endl;
system("pause");
return 0;
}
那么有什么方法可以从文件中读取并在控制台中显示输出,直到给出来自键盘的另一个输入。提前致谢
【问题讨论】:
-
试试
system( "PAUSE" ); -
和以前一样。
-
在某个终端(在您的 IDE 之外)运行您的程序
-
使用
freopen重新指向stdin会限制您通过键盘从用户那里获取更多输入的选项。 -
freopen会这样做,并且没有简单的方法可以恢复。为什么不使用std::ifstream fin("input.txt");和后来的fin >> n;?
标签: c++ visual-c++ freopen