#include <iostream>
#include <sstream>
#include <string>
struct Customer
{
std::string name;
std::string id;
float loanAmount;
};
std::istream& operator >> (std::istream& is, Customer& cust)
{
std::getline(is, cust.name); // getline from <string>
is >> cust.id;
is >> cust.loanAmount;
is.ignore(1024, '\n'); // after reading the loanAmount, skip the trailing '\n'
return is;
}
int main()
{
std::stringstream ss;
ss << "Williams, Bill\n"
<< "567382910\n"
<< 380.86f << "\n"
<< "Davidson, Chad\n"
<< "435435435\n"
<< 400.00f;
Customer c;
ss >> c;
std::cout << c.name << "\t" << c.id << "\t" << c.loanAmount << std::endl;
ss >> c;
std::cout << c.name << "\t" << c.id << "\t" << c.loanAmount << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4KCnN0cnVjdCBDdXN0b21lcgp7CiAgc3RkOjpzdHJpbmcgbmFtZTsKICBzdGQ6OnN0cmluZyBpZDsKICBmbG9hdCBsb2FuQW1vdW50Owp9OwoKc3RkOjppc3RyZWFtJiBvcGVyYXRvciA+PiAoc3RkOjppc3RyZWFtJiBpcywgQ3VzdG9tZXImIGN1c3QpCnsKICAgIHN0ZDo6Z2V0bGluZShpcywgY3VzdC5uYW1lKTsgLy8gZ2V0bGluZSBmcm9tIDxzdHJpbmc+CiAgICBpcyA+PiBjdXN0LmlkOwogICAgaXMgPj4gY3VzdC5sb2FuQW1vdW50OwogICAgaXMuaWdub3JlKDEwMjQsICdcbicpOyAvLyBhZnRlciByZWFkaW5nIHRoZSBsb2FuQW1vdW50LCBza2lwIHRoZSB0cmFpbGluZyAnXG4nCiAgICByZXR1cm4gaXM7Cn0KCmludCBtYWluKCkKewogIHN0ZDo6c3RyaW5nc3RyZWFtIHNzOwoKICBzcyA8PCAiV2lsbGlhbXMsIEJpbGxcbiIKICAgICA8PCAiNTY3MzgyOTEwXG4iCiAgICAgPDwgMzgwLjg2ZiA8PCAiXG4iCiAgICAgPDwgIkRhdmlkc29uL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