No Output to the Screen

Someone please help me figure out why this code isn't producing any screen output. I've been racking my brain all weekend and my solutions looks like the console...empty. When I compile the program, it seems to be fine. I run the program and the MS DOS window pops up but the cursor just blinks...Nothing

Someone please HELP me

This is the code I've written (using code blocks):



#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>

using namespace std;

struct Month {
unsigned int year;
unsigned int month;
unsigned int day;
unsigned int time;

};

int main()
{

ifstream file_to_read("data_in.txt");

vector<Month> month_array;

while(!file_to_read.eof())
{

if(!isdigit(file_to_read.peek()))
{
file_to_read.ignore();
continue;
}

Month month_read;

file_to_read.ignore(1);
file_to_read >> setw(4) >> month_read.year;
file_to_read.ignore(1);
file_to_read >> setw(2) >> month_read.month;
file_to_read.ignore(1);
file_to_read >> setw(2) >> month_read.day;
file_to_read.ignore(2);
file_to_read >> setw(6) >> month_read.time;

month_array.push_back(month_read);

cout << "Date and Times read are:\n";
for(unsigned int j = 0; j < month_array.size(); j++)
cout << setw(4) << month_array[j].year << ' ' << month_array[j].month << ' ' << month_array[j].day << ' ' << month_array[j].time << '\n';

return 0;
}
}

The Data file (Data_in.txt)looks like this:

"2011-02-27",20:00,21.2,11,-10,-41,0
"2011-02-27",21:00,9.3,12,-10,41,0
...
...
...
...


Stop racking brain, start debugging.

Build this and get the code to tell you what it's up to.


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
53
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>

using namespace std;

struct Month {
unsigned int year;
unsigned int month;
unsigned int day;
unsigned int time;

};

int main()
{

ifstream file_to_read("data_in.txt");

vector<Month> month_array;

 cout << "About to enter while loop..." << endl;
while(!file_to_read.eof())
{
cout << "About to check digit ..." << endl;
if(!isdigit(file_to_read.peek()))
{
cout << "Not a digit ..." << endl;
file_to_read.ignore();
continue;
}

Month month_read;
cout << "About to read from file ..." << endl;
file_to_read.ignore(1);
file_to_read >> setw(4) >> month_read.year;
file_to_read.ignore(1);
file_to_read >> setw(2) >> month_read.month;
file_to_read.ignore(1);
file_to_read >> setw(2) >> month_read.day;
file_to_read.ignore(2);
file_to_read >> setw(6) >> month_read.time;

month_array.push_back(month_read);

cout << "Date and Times read are:\n";
for(unsigned int j = 0; j < month_array.size(); j++)
cout << setw(4) << month_array[j].year << ' ' << month_array[j].month << ' ' << month_array[j].day << ' ' << month_array[j].time << '\n';

return 0;
}
}
Last edited on
Moschops,

Thanks for the suggestion, but I tried that (or something similar) before I posted the code, I think the problem is more fundamental. I'll be darned if I can figure it out.

Robert

With the code I posted, and this as data_file.txt

1
2
"2011-02-27",20:00,21.2,11,-10,-41,0
"2011-02-27",21:00,9.3,12,-10,41,0


I get the following output:

1
2
3
4
5
6
About to check digit ...
Not a digit ...
About to check digit ...
About to read from file ...
Date and Times read are:
  11 2 27 20


My guess is that you're not opening the file. Add some debug to check if the file open works. Be sure that the data file is in the same directory as your executable.
Topic archived. No new replies allowed.