-
Notifications
You must be signed in to change notification settings - Fork 1
/
Initialize.cpp
52 lines (41 loc) · 1.17 KB
/
Initialize.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// This file only contains the definition of the 'initialize' function
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <stdlib.h>
#include "Initialize.h"
using namespace std; //Because YOLO
/* This function reads the initial values in the text file and
* stores them in a 'double' array.*/
void initialize( string fileName , double * number ) // 'number' is a pointer to the first element of the array
{
string line;
ifstream conditionsFile( fileName.c_str() );
int counter = 0;
double temp = 0;
if ( conditionsFile.is_open() )
{
while ( getline ( conditionsFile , line ) )
{
// If the line starts with '#', then it is a comment and we ignore the line.
if( line[0] != '#' )
{
//Put the content of each line in 'lineContent'
istringstream lineContent( line );
//Take each number in 'lineContent' and put it in an element of the array
while ( lineContent >> temp )
{
number[counter] = temp;
counter++;
}
}
}
conditionsFile.close();
}
else //If the file cannot be read
{
cout << "Unable to read file.";
exit(1);
}
}