I'm trying to read a line of information from a file and I'm running into a problem while reading the double. I need the program to read and display the number 5693.3 and it's displaying some weird long number including a symbol. Any help is greatly appreciated!
This is the line of information:
John H. Doe 1001 H 5693.3
The command window outputs this:
John H. Doe 1001 H 5693.3-858993460╠-9.25596e+61
Yes, I see where I went wrong. However, now I'm stuck on how to get the name stored in a string including white space characters, and then get the rest of the input stored separately as an int, char, and double?
Edit: Here is the entire file I need to read and extract data from line by line. I need the name extraction to work for all types of names.
John H. Doe 1001 H 5693.3
James Randolph, Jr. 3333 H 1000.0
Sara Lawrence-Smith 2456 H 3999999.5
Good Time Industries 4678 C 10000000.1
Big Business, Inc. 6757 I 12500849.9
Mom and Pop Shop 5002 C 4000000.7
The O'Leary Company 8022 I 9999999.9
Alright, so far I've gotten this piece of program to read the lines and separate the pieces into the data types I need. However, it is creating and unhandled exception at accNum = stoi(m[2]);
Here is the modified function code that I changed in the above program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
void readBillingRecord(ifstream& fin, string& name, int& accNum, char& type, double& usage)
{
string line;
regex r{ R"(([\D]*)(\d*) (\w) (\d*.?\d*))" };
smatch m;
while (getline(fin, line))
{
regex_match(line, m, r);
name = m[1];
accNum = stoi(m[2]);
type = string{m[3]}[0];
usage = stod(m[4]);
cout << name << accNum << type << usage << endl;
}
}