So i am working on this program that has to read a file contacting property address and the amount of property tax due. The file looks like this:
151 Acorn
500
161 Acorn
1500
200 Main
15000
500 Arcade
25000
181 Acorn
6000
120 Xenia
1000
200 Acorn
20000
1 2 3 4 5 6 7 8 9 10 11
|
infile.open("prog3Input.txt");
if (infile.fail())
cout << "error opening file\n";
for (int i =0; i < SIZE; i++)
{
getline(infile,address[i]);
infile >> amtDue[i];
cout << address[i] << endl;
cout << "$" << amtDue[i] << endl;
}
| |
after this executes i get this:
151 Acorn
$500
$161
Acorn
$1500
$200
Main
$15000
$500
Arcade
$25000
|
i used some breakpoints to see what was actually going into the string and i get this:
amtDue double [7]
[0] double 500 500
[1] double 161 161
[2] double 1500 1500
[3] double 200 200
[4] double 15000 15000
[5] double 500 500
[6] double 25000 25000
address string [7]
[0] std::__1::string "151 Acorn\r"
[1] std::__1::string "\r"
[2] std::__1::string " Acorn\r"
[3] std::__1::string "\r"
[4] std::__1::string " Main\r"
[5] std::__1::string "\r"
[6] std::__1::string " Arcade\r"
what the heck am i doing wrong here? i tried a cin.ignor() to no avail.