Arrays from text file

How do i store double/integer from a text file into an array. I have used two columns one is the time and the other is amplitude, they both have 361 rows of doubles. I need to get the amplitude (which is the second column) into an array, any ideas how to do this? I am a noob at c++
I would approach this step by step. First write code to open the file and read the values, and display (cout) the amplitude value. When you've done that, modify the code to store the value instead of display it.


Files tutorial:
http://www.cplusplus.com/doc/tutorial/files/
Last edited on
closed account (oGN8b7Xj)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <fstream>

int main () 
{
  std::ifstream ifs ("amplitudes.txt", std::ifstream::in);

  double dTime;
  double aAmplitude[361];

  for (int (0) ; i < 361 ; ++i)
  {
     ifs >> dTime >> aAmplitude[i];
  }

  ifs.close();

  return 0;
}
Last edited on
Topic archived. No new replies allowed.