如何将特定字符从TXT文件输出到特定点
How do I output specific characters from a txt file to specific points?
教程的第一个任务,我已经很困惑了,
对,我应该将3个数字写入文本文件,打开该文件,输出所有3个数字和平均值。设法完成了前两个部分,但我已经在实际输出部分撞到了墙。
这是文本文件的内容,就像文件中所显示的那样:
25
10
12
这是我到目前为止的代码:
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
// Create an ifstream input stream for reading of data from the file
ifstream inFile;
inFile.open("ProgrammingIsFun.txt");
// Create an ofstream output stream for writing data to a file
ofstream outFile;
outFile.open("Results.out");
cout << "The first integer is " << endl;
cout << "The second integer is " << endl;
cout << "The third integer is " << endl;
cout << "The average is " << endl;
// Close the files since we're done with them
outFile.close();
inFile.close();
system("Pause");
return 0;
}
据我了解,txt文件的内容只能包含这3个数字,而没有其他内容(虽然我可能错了)
任何帮助都将不胜感激。
我猜想,从文件中读取整数的首选方法是:
int first, second, third;
inFile >> first;
inFile >> second;
inFile >> third;
然后,您可以使用&lt;&lt;可以类似地输出Outfile的操作员。
相关文章:
- 如何在 的开头<x>和结尾<y>之间更改带有文件输出的字符串的值
- C++对象数组的文件输出
- bcdedit 文件输出不起作用,但其他命令可以
- 如何从文本文件输出数据?(学生成绩单计划)
- 使用 C++文件 I/O 输出 pdf 文件
- C 文件输出垃圾
- 从堆栈中读取字符后,如何修复不正确的文件输出
- C++:具有随机名称的文件输出
- 在命令提示符下看到换行符,但在文件输出中可以看到 相同的字符串
- 生成文件不会生成预期的文件输出
- C++11 fgetc 在"r+b"模式下使用时向我的文件输出 0
- 使用函数从文件输出
- GCC.obj文件输出不具有确定性(.debug_info,PROGPITS部分)
- C cstdiofile :: Writestring给出了不正确的文件输出
- C 输出:STD :: COUT和文件输出没有相同的内容
- GCC和MSVC之间的文件输出不一致
- C++文件输出奇怪的数字,并且部分代码没有运行
- 如何将特定字符从TXT文件输出到特定点
- C 调用从TXT文件输出信息的函数
- 将交易从文本文件输出到屏幕