Hi,
I'm creating a program which stores information, lets say about cars in a text file.
Up until now, I've only read and wrote to text files using variables, for example:
cars.txt:
And I would open a stream to write and read to the file.Code:Ford Mondeo 5 25.25 Vauxhall Vectra 5 10.10
But now I'm using an OO approach and am unsure on how to write objects to the text file, eg:
Function to create a new object:
How would I store the object in the text file? At the moment I'm trying:Code:void createAcar() { cars car1; car1.manufacturer = Ford; car1.model = Mondeo; car1.door = 5; car1.mpg = 25.25 }
But Visual Studio says " 'carTextFile' : undeclared identifier ".Code:carTextFile >> car1; //carTextFile is the name of the stream
I'm thinking this is due to scope, but am wondering if my method of storing the objects in the text file is way off.
Thanks for any advice![]()



LinkBack URL
About LinkBacks




CornedBee