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:
Code:
Ford Mondeo 5 25.25
Vauxhall Vectra 5 10.10
And I would open a stream to write and read to the file.
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:
Code:
void createAcar()
{
cars car1;
car1.manufacturer = Ford;
car1.model = Mondeo;
car1.door = 5;
car1.mpg = 25.25
}
How would I store the object in the text file? At the moment I'm trying:
Code:
carTextFile >> car1; //carTextFile is the name of the stream
But Visual Studio says " 'carTextFile' : undeclared identifier ".
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