Ok guys, I spent all of yesterday understanding a binary file and creating a binary file's and I have managed to understand them pretty well and found some great websites explaining them. I have finished my code and it does not work, but I know whats wrong, I just need to know how to fix it!! I will post the code and then post my problem at the end!
//Sets to default values
Car::Car() {
make = " ";
model = " ";
color = " ";
year = 0;
mileage = 0;
}
What will I set the char's make, model, and color = to??
when I hover over make, model or color, it says "Expression must be modifiable lvalue" I also get other errors but I know these are all related to this error and when i figure out how to do the char, it will work!
As make, model and color are char arrays, which you are going to use as string:
eg "Ford", "Cortina", "Blue" and you want to initialise them to empty strings, then you could just do this:
1>------ Build started: Project: FileReading, Configuration: Debug Win32 ------
1> Car.cpp
1>\filereading\carclass.h(48): error C2440: '=' : cannot convert from 'const char [14]' to 'char [40]'
1> There is no context in which this conversion is possible
1>\filereading\carclass.h(49): error C2440: '=' : cannot convert from 'const char [14]' to 'char [40]'
1> There is no context in which this conversion is possible
1>\filereading\carclass.h(50): error C2440: '=' : cannot convert from 'const char [14]' to 'char [20]'
1> There is no context in which this conversion is possible
1>\filereading\carclass.h(56): error C2106: '=' : left operand must be l-value
1>\filereading\carclass.h(57): error C2440: '=' : cannot convert from 'char' to 'char [40]'
1> There are no conversions to array types, although there are conversions to references or pointers to arrays
1>\filereading\carclass.h(58): error C2440: '=' : cannot convert from 'char' to 'char [20]'
1> There are no conversions to array types, although there are conversions to references or pointers to arrays
1>\filereading\carclass.h(65): error C2440: '=' : cannot convert from 'char' to 'char [40]'
1> There are no conversions to array types, although there are conversions to references or pointers to arrays
1>\filereading\carclass.h(69): error C2440: '=' : cannot convert from 'char' to 'char [40]'
1> There are no conversions to array types, although there are conversions to references or pointers to arrays
1>\filereading\carclass.h(73): error C2440: '=' : cannot convert from 'char' to 'char [20]'
1> There are no conversions to array types, although there are conversions to references or pointers to arrays
1>\filereading\carclass.h(86): error C2440: 'return' : cannot convert from 'char [40]' to 'char'
1> There is no context in which this conversion is possible
1>\filereading\carclass.h(89): error C2440: 'return' : cannot convert from 'char [40]' to 'char'
1> There is no context in which this conversion is possible
1>\filereading\carclass.h(92): error C2440: 'return' : cannot convert from 'char [20]' to 'char'
1> There is no context in which this conversion is possible
1>\filereading\car.cpp(24): error C2665: 'Car::Car' : none of the 3 overloads could convert all the argument types
1> \filereading\carclass.h(24): could be 'Car::Car(char,char,char,int,int)'
1> while trying to match the argument list '(const char [8], const char [4], const char [7], int, int)'
1>\filereading\car.cpp(25): error C2665: 'Car::Car' : none of the 3 overloads could convert all the argument types
1> \filereading\carclass.h(24): could be 'Car::Car(char,char,char,int,int)'
1> while trying to match the argument list '(const char [5], const char [8], const char [4], int, int)'
1>\filereading\car.cpp(26): error C2665: 'Car::Car' : none of the 3 overloads could convert all the argument types
1> \filereading\carclass.h(24): could be 'Car::Car(char,char,char,int,int)'
1> while trying to match the argument list '(const char [10], const char [8], const char [6], int, int)'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Just about- Like this.
Note:
1. I have made no buffer overflow check when copying the arrays - but you should.
2. We can do away with a default constructor if we give all the parameters in the other constructor all default values.
3. We can make the get functions constant
4. As you can probably guess, it is easier to use theC++ string type rather than char arrays.
With regard to points 2 and 3 - have you learnt about default parameter values or constant member functions yet??
Ok here is my new code guys, and it is creating the file that I want! But its not reading from that file and printing on the screen! IT should write the array of cars to the file, read the array of cars and print them on the screen and then re-write the array of cars..
Also, should I save this as a .bin file or a .dat file or .txt file or what??
CLASS