Hello everyone, it's been a while since I've done anything in C++ so please excuse the errors, modularity, etc. For this homework assignment we basically have to write a program that reads certain data from a file into an array, (My professor says we don't have to use the array if we can "analyze the data stream as it comes in" but I can't figure that out and I haven't been able to find out how to do it online unless you all can help me.), count how many different numbers are in the file, use a mergesort to put the numbers in order, etc.
The problem so far is how to get the second row of data out of the file and put it in an array.
For example if my file look like this:
1. 20
2. 15
3. 77
4. 15
5. 29
6. 77
How would I get the 20, 15, etc. into an array without reading the 1. , 2. , 3. ?
I have more questions but I need to figure this out first before I get into that. Thanks in advance!!!
Here's my code so far:
The problem so far is how to get the second row of data out of the file and put it in an array.
For example if my file look like this:
1. 20
2. 15
3. 77
4. 15
5. 29
6. 77
How would I get the 20, 15, etc. into an array without reading the 1. , 2. , 3. ?
I have more questions but I need to figure this out first before I get into that. Thanks in advance!!!
Here's my code so far:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main (int argc, char * const argv[]) {
std::cout << "Hello, World!\n";
double time_to_accesstrack, sort_coeficient;
string input_filename;
cout << "Welcome to the I/O reordering analyzer" << endl;
cout << "\n"<< endl;
cout << "How long in milleseconds does the drive need to access a track?";
cin >> time_to_accesstrack;
cout << "What is the CPU's sort coefficient (in milliseconds)?";
cin >> sort_coeficient;
cout << "What is the name of the test data file?";
cin >> input_filename;
cout << "\n" << endl;
cout << "Analyzing..."<< endl;
while (true)
{
string infilename;
getline( cin, input_filename );
infile.open( input_filename.c_str() );
if(!inFile) {
cout << endl << "Failed to open file " << input_filename;
return 1;
}
long n = 0;
while(!inFile.eof()) {
inFile >> n;
cout << std::setw(15) << n;
}
cout << endl;
return 0;
}
}