如何将值从输入文件读取到屏幕

How to read values from an input file to the screen

本文关键字:文件 读取 屏幕 输入      更新时间:2023-10-16

Is

cout.put(value);

在 C++ 中将值从文件读取到屏幕有效吗?

你的问题相当模棱两可。假设文件中有一些数据(例如整数),您可以将它们提取到局部变量中并在屏幕上打印出来。

...
int k;
ifstream i;
i.open(yourfilename.txt);
k << i;
cout << i;
...

假设value的类型可以通过cout输出,则

cout << value;

应该工作得很好。