Hello and thank you for taking the time to help.
I am having an issue oh how to read an input file with mixed data types to read into a struct. The file is a store report of balances customers owe. I have looked on google and youtube and I'm not finding exactly what I'm looking for. most example either read in data that is in one column format or they read in the data from cin.
My assignment has 10 customers and the data looks similar to this (account#, name, address, balance)
123456. Smith, Joe R. 234 Happy ln. -30.92
ok so some of the things that I have tried that looked promising did not help.
1 2 3 4 5 6 7 8 9 10 11 12
|
char acc[10];
char name[20];
char adrs[20];
float bal;
inFile.get(acc, 10);
inFile.get(name, 20);
inFile.get(adrs, 20);
inFile >> bal;
//this only returns the 1st line and the second line nothing
|
1 2 3 4 5 6 7 8 9
|
string acc;
string name;
string adrs;
string bal;
getline(inFile, acc);
//Same for the others but no luck here either
|
I am aware of using to <sstream> to convert between data types but I cannot get all the data in a consistent format. Some names have middle initials and others don't so that messes up some loops if I try to read everything in as a string.
We are still not at pointers or vectors. we just started structs last week, and I have been trying different things for two days.
I feel that I need to read the data in as char but I don't think I'm doing it correctly, on my assignment my professor mentions where some values end and begin (spaces and length ) so that the hint I'm going off of.
Thank you.