Hi, i have been working on trying to do this for a while now. I applied for a job in c++ and the person gave me a task to test my skill... needless to say that i didn't get the job but i am still working on it to figure out how it should work... and the main problem i have been having is reading from the file correctly. my code is as below and i have attatched a test file for use... the overall program is supposed to look at the res and dem and then try to work out the best use of resources. i got a little ahead of myself when i applied for the job i will admit but now is the time for learning from that. if anyone has any ideas as to how to get it to work right at the moment i just need it to display right it needs to read as follows :
res <id><start time><finish time><location x><location y>< skills(n)>
dem <id><duration><skill><start time><finish time><location x><location y><revenue>
#include <iostream>
#include <fstream>
#include <istream>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;
typedef unsigned int uint;
int main()
{
char filename[256];
cin.getline(filename, 256);
ifstream currentfile;
currentfile.open(filename);
string type;
uint id;
uint starttime;
uint finishtime;
float locx;
float locy;
string instancename;
uint duration;
uint skill;
while (currentfile)
{
if (currentfile == "instance")
{
currentfile >> instancename;
}
if (currentfile == "res")
{
type = "res";
currentfile >> id >> starttime >> finishtime >> locx >> locy;
}
if (currentfile == "dem")
{
type = "dem";
currentfile >> id >> duration >> skill >> locx >> locy >> starttime >> finishtime;
}
if (type == "res")
{
cout << type << "\n";
cout << id << "\n";
cout << starttime << "\n";
cout << finishtime << "\n";
cout << locx << "\n";
cout << locy << "\n";
}
if (type == "dem")
{
cout << type << "\n";
cout << id << "\n";
cout << duration << "\n";
cout << skill << "\n";
cout << locx << "\n";
cout << locy << "\n";
cout << starttime << "\n";
cout << finishtime << "\n";
}
}
system("PAUSE");
return 0;
}
it reads the file but doesn't store it to the variables they way i need it to.... once i get that part sorted i need to work on making class arrays so that i can use the information to analyse the data for the rest of the application.
any help would be appreciated... i have searched a few of the threads here..... searched the internet... and even all my course material and nothing seems to help that much. Any help is appreciated.