I have a text file that contains namename,age age,salary salary,hoursWorked hoursWorked,randomText randomText and wereare filled with different delimiters.
textfileText file:
susan:25-2600,28[asd]
mary:21-2200,38[asd]
john:23-3400,46[asd]
insteadInstead of breaking them into individual strings using the code shown below.:
string name,age,salary,hoursWorked,randomText;
ifstream readFile("textfile.txt");
while(getline(readFile,line)) {
stringstream iss(line);
getline(iss, name, ':');
getline(iss, age, '-');
getline(iss, salary, ',');
getline(iss, hoursWorked, '[');
getline(iss, randomText, ']');
}
readFile.close();
whatWhat are some better strategies other than coding it this way?
sideNoteSide note
I decleareddeclared all the variables to strings because of getlinethe getline() method.