i need to read a file to my simulation in C++, the file has to be on this format:
# Comments
# Comments
nameOfTheMarket
timeOfSimulation
averageTime
numberOfCashiers
cashierName1 quality1 salary1
cashierName2 quality2 salary2
- - -
cashierNameN qualityN salaryN
#End
It's the first time i deal with files, but i was reading around and tried to do this way:
int main ()
{
string marketName, cashierName;
int counter = 0;
int counter2 = 0;
int simulationTime,averageTime, numberOfCashiers;
string info, test;
ifstream input("/home/meucomputador/workspace/Testezin/src/naocompre.dat");
if(input.is_open()) {
while(!input.eof()) {
getline(input,info);
cout<<info<<endl;
if(info[0] != '#') {
counter++;
}
switch(counter) {
case 1:
marketName = info;
break;
case 2:
stringstream(info) >> simulationTime;
break;
case 3:
stringstream(info) >> averageTime;
break;
case 4:
stringstream(info) >> numberOfCashiers;
break;
default:
//how to read the 3 information at the same line?
for(int i = 0; i < info.length(); i++) {
while(info[i] != ' ')
counter2++;
}
cashierName = info.substr(0,counter2+1);
}
}
}
return 0;
};
My difficulty consists on reading the cashier's names , quality and salary. Do i really need to use the "while(info[i] != ' ')"? That's not working.