Hello everyone,
I was looking for some help with a program I am currently writing. I am to be given an input file with the following format:
# of temperature readings
a time stamp followed by a temperature (note that there is one blank space between the time stamp and the temperature)
I am then to convert the time from:
YYYYMMDDHHMM (e.g. 200708201425)
to
08/20/2007 14:25.
The file will have data structured as:
2
200707211245 F70.5
200708220812 C19.97
and the output will look something like this:
BIODATA Formatted Ouput
te.mp C --- recorded on MM/DD/YYYY at 12:45
te.mp C --- recorded on MM/DD/YYYY at 08:12
I've been doing piece by piece so everything was working before I tried adding the temp. When compiling, everything goes as normal. However, when attempting to run the program it immediately freezes. I'm thinking the temp has to be addressed in a completely different manner, because of the F/C in front of it as well as the white space before it. Any idea what I'm doing wrong or any advice on what to read to address this?
Also, I cannot use arrays for this program. I am just to process each temperature as it's read in.
Here's mah code:
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
string getYear(string date)
{
string year = date.substr(0,4);
return year;
}
string getMonth(string date)
{
string month = date.substr(4,2);
return month;
}
string getDay(string date)
{
string day = date.substr(6,2);
return day;
}
string getHour(string date)
{
string hour = date.substr(8,2);
return hour;
}
string getMinute(string date)
{
string minute = date.substr(10, 2);
return minute;
}
string getTemp(string date)
{
string temp = date.substr(14,date.length());
return temp;
}
int main ()
{
int numOfReadings;
ifstream inFile;
inFile.open ("biodata.dat");
inFile >> numOfReadings;
for (int i=0; i < numOfReadings; i++)
{
string date;
inFile >> date;
string year = getYear(date);
string month = getMonth(date);
string day = getDay(date);
string hour = getHour(date);
string minute = getMinute(date);
string temp = getTemp(date);
cout << temp << endl; // test for temp retrieval
}
system("pause");
return 0;
}
|
Thanks for the help and I appreciate your time!
Also, the error I receive in the cmd window is:
This application has requested the Runtime to terminate it in an unusual way. blah blah blah