首页 > 解决方案 > 读取四个数据文件并使用函数将它们放入结构数组的最佳方法是什么?

问题描述

首先,我需要从四个输入文件中读取数据。其次,我需要创建一个结构数组并将数据存储到结构中。第三,我必须对数据进行一些操作。最后,我要将处理后的数据打印到输出文件中。

首先,我从来没有一次从多个文件中读取数据。第二,我以前从未使用过结构,更不用说结构数组了。我坚持使用从所有四个文件中读取数据并将该数据存储到结构数组中的最有效方法。

因此,我的问题是,读取数据的最佳方法是什么?

几个小时以来,我一直在考虑四种不同的方法。每个都包含一个带有“非文件结尾”布尔表达式的 while 循环。

标签: c++arraysinputstruct

解决方案


#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;
}

希望这会帮助你。


推荐阅读