deekakes
asked on
How to ignore certain white spaces when reading an object of strings.
Hello experts:
I am trying to read an object into a list and
I can't figure out how to ignore white space in the title of a Book object. (See below for overloaded >> operator function.) I heard that it might be better to read the object members into stringstream with a getline but can't figure out exactly how. Any suggestions would be greatly appreciated (have spent days trying to figure this out!).
Here is one line from the data file I'm trying to read into an object:
Herbert Schildt, C: The Complete Reference 0-07-212124-6 Mcgraw Hill 2000 805 24.99 paperback
The data members of my Book object are:
string author_first_name;
string author_last_name;
string title;
string isbn;
string publisher;
string pub_year;
string page_count;
string price;
string book_type;
.......................... .......... .......... .......... .......... ..
istream& operator>>(istream& infile, Book& a_book)
{
infile >> a_book.author_first_name >> a_book.author_last_name
>> a_book.title >> a_book.publisher >> a_book.isbn
>> a_book.pub_year >> a_book.page_count
>> a_book.price >> a_book.book_type;
return infile;
}
I am trying to read an object into a list and
I can't figure out how to ignore white space in the title of a Book object. (See below for overloaded >> operator function.) I heard that it might be better to read the object members into stringstream with a getline but can't figure out exactly how. Any suggestions would be greatly appreciated (have spent days trying to figure this out!).
Here is one line from the data file I'm trying to read into an object:
Herbert Schildt, C: The Complete Reference 0-07-212124-6 Mcgraw Hill 2000 805 24.99 paperback
The data members of my Book object are:
string author_first_name;
string author_last_name;
string title;
string isbn;
string publisher;
string pub_year;
string page_count;
string price;
string book_type;
..........................
istream& operator>>(istream& infile, Book& a_book)
{
infile >> a_book.author_first_name >> a_book.author_last_name
>> a_book.title >> a_book.publisher >> a_book.isbn
>> a_book.pub_year >> a_book.page_count
>> a_book.price >> a_book.book_type;
return infile;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you....