Reputation: 97
I have a file that looks like this:
Category ID Description
1 Pay Check
2 Groceries
3 Utilities
14 Rent
25 Mortgage
6 Travel
7 Refund
8 Restaurant
9 College Fund
10 Transfer From Savings
I created an input file stream to read in the Category ID, then used getline() to read the Description. My problem is that whenever using getline() to read the Description into strings, it keeps the whitespace before the actual string. Is there any way to ignore the whitespace when storing it?
Upvotes: 1
Views: 3296
Reputation: 96790
Use std::ws
:
while (std::getline(in >> std::ws, line))
// ^^^^^^^^^^^^^
Upvotes: 7