Question: struct Item { Item(std::string name, int magic=0) : name{name}, magic{magic} {} std::string name; /// Item name int magic = 0; /// Amount of magic the

struct Item { Item(std::string name, int magic=0) : name{name}, magic{magic} {} std::string name; /// Item name int magic = 0; /// Amount of "magic" the item is imbued with std::ostream& write( std::ostream& fout ) const; }; std::ostream& operator<<( std::ostream& fout, const Item& item );

Implement the write() method and the overloaded stream insertion operator in the Item.cpp file.

The write() method should display the name (in a 30 character block), and magic value of a game item, with a space between them. Write this method now, using iomanips setiosflags(std::ios::left) to left justify the strings and resetiosflags(std::ios::left) to undo the justification after use. The write() method should return the stream after using it. The overloaded operator << simply calls write(); complete this function as well.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!