c++ - 读取四个数据文件并使用函数将它们放入结构数组的最佳方法是什么?
问题描述
首先,我需要从四个输入文件中读取数据。其次,我需要创建一个结构数组并将数据存储到结构中。第三,我必须对数据进行一些操作。最后,我要将处理后的数据打印到输出文件中。
首先,我从来没有一次从多个文件中读取数据。第二,我以前从未使用过结构,更不用说结构数组了。我坚持使用从所有四个文件中读取数据并将该数据存储到结构数组中的最有效方法。
因此,我的问题是,读取数据的最佳方法是什么?
几个小时以来,我一直在考虑四种不同的方法。每个都包含一个带有“非文件结尾”布尔表达式的 while 循环。
解决方案
#include <iostream>
#include <fstream>
using namespace std;
int main(){
char text[200]; // store data in an array
fstream file;
file.open ("example.txt", ios::out | ios::in ); // file name is exam for reading
// Reding from file
file >> text;
cout << text << endl; // print data of file thought array
//closing the file
file.close();
return 0;
}
希望这会帮助你。
推荐阅读
- pandas - 如何将ndarray转换为pandas DataFrame
- r - 使用 ibmdbR 包在 R 对象中追加和更新 DB2 表行
- sql-server - SQL Express - 我可以对现有表进行分区以解决 10GB 文件大小限制吗?
- wpf - 将对象绑定到组合框和文本框
- c - memcpy:GCC 或实现优化?
- javascript - 使用 JavaScript 创建文件并在单击按钮时下载
- unit-testing - 使用 github.com/jarcoal/httpmock 验证请求正文
- angular - Angular 7中ng-cloak(angularjs)的替代方法是布尔变量而不是对象
- python - 有没有办法在给定点找到多边形?
- android - 有什么方法可以禁用片段上的深层链接?