View Single Post
  #6 (permalink)  
Old May 19th, 2016, 02:00 PM
Marc Gregoire Marc Gregoire is offline
Wrox Author
Points: 220, Level: 4
Points: 220, Level: 4 Points: 220, Level: 4 Points: 220, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 49
Thanks: 0
Thanked 4 Times in 4 Posts
Default

One option is to write them as follows:
Code:
outFile << quoted(getDescription()) << ' ' << getSize() << ' ' << boolalpha << getHasChocolateChips() << '\n';
Note that I'm using the quoted() manipulator and replaced the ^ with spaces.
The following is then one way to read the data back:
Code:
	while (!inFile.eof())
	{
		description = "";
		inFile >> quoted(description);
		if (description.empty())
		{
			break;
		}
		inFile >> size >> boolalpha >> chips;
		cout << "inFile: " << description << " " << size << " " << boolalpha << chips << endl;
	}