|
Hello,
I have the code below which compiles with no errors, however no data is printed to teh screen... i think the file is not being read (somehow not being recognised, so now data is there).
Can anyone spot what's wrong? I adapted this from a previous post by Samir.
thanks for any help.
My file that i am trying to reference is on my hard disk, but about 4 directories down (do i need to show the full path - have tried that but no luck but could be doing something wrong)
J
"#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
using namespace std;
// A structure used to store time
struct Date {
unsigned int year;
unsigned int month;
float day;
};
int main()
{
// STEP 1: READ THE FILE
ifstream file_to_read;
file_to_read.open("/forum/AAPL.txt");
const int max_num_of_char_in_a_line = 512,// Maximum number of characters expected in a single line in the header
num_of_header_lines = 0; // Number of header files to skip
// STEP2: SKIP ALL THE HEADER LINES
for(int j = 0; j < num_of_header_lines; ++j)
file_to_read.ignore(max_num_of_char_in_a_line, '\n');
vector<Date> date_array;
vector<float> open_array, high_array, low_array, close_array, volume_array, openinterest_array, tot_volume_array, tot_openinterest_array;
while(!file_to_read.eof())
{
Date date_read;
file_to_read >> setw(4) >> date_read.year;
file_to_read >> setw(2) >> date_read.month;
file_to_read >> date_read.day;
date_array.push_back(date_read);
float open, high, low, close, volume, openinterest, tot_volume, tot_openinterest;
file_to_read >> open >> high >> low >> close >> volume >> openinterest >> tot_volume >> tot_openinterest;;
open_array.push_back(open);
high_array.push_back(high);
low_array.push_back(low);
close_array.push_back(close);
volume_array.push_back(volume);
openinterest_array.push_back(openinterest);
tot_volume_array.push_back(tot_volume);
tot_openinterest_array.push_back(tot_openinterest);
}
// STEP4: USE THE DATA READ AND STORED IN THE ARRAY HOW EVER YOU WANT
cout << "Dates read are:\n";
for(vector<Date>::size_type j = 0; j < date_array.size(); ++j)
cout << date_array[j].year << '/index.html' << date_array[j].month << '/index.html' << date_array[j].day << '\n';
cout << "Close prices are:\n";
for(vector<float>::size_type j = 0; j < close_array.size(); ++j)
cout << close_array[j] << '\n';
return 0;
}"
|
|
|
|
|
|
|
// |