function not showing any input

I need to create Three classes , namely:
1. Motorbikes
2. Vans
3. Trucks

all of them have the following:
private:
string vehicleColour;
int noOfWheels;
int noOfDoors;
int noOfSeats;
public:
void setVehicleColour(string colour);
void setNoOfDoors(int doornumber);
void setNoOfSeats(int seatNumber);
string getVehicleColour();
int getNoOfDoors();
int getNoOfSeats();
string toString();

I have to get user input and have all the info displayed using the toString() function. I tried the following two methods out but it doesnt work at all.
1
2
3
4
5
6
7
8
9
10
string toString()
{
    string colour = getVehicleColour();
    //no of wheels is pre-set so motorbikes will be 2, for vans4 and trucks 18
    int noOfWheels = 2;
    int noOfSeats = getNoOfSeats();
    int noOfDoors = getNoOfDoors();
    string specs = "Vehicle colour: " + colour + "No of wheels: " + noOfWheels "No of seats: " + noOfSeats + "No of doors: " + noOfDoors;
   return specs;
}


I also tried this:
1
2
3
4
5
6
7
8
9
10
string toString()
{
    string colour = getVehicleColour();
    //no of wheels is pre-set so motorbikes will be 2, for vans4 and trucks 18
    int noOfWheels = 2;
    int noOfSeats = getNoOfSeats();
    int noOfDoors = getNoOfDoors();
    string specs = "Vehicle colour: {0} No of wheels: {1} No of seats: {2} No of doors: {3}", colour,noOfWheels,noOfSeats, noOfDoors;
   return specs;
}


I don't know can you use a '+' to join strings together
your help will be highly appreciated
Are you just caling the function and not using its return value? You need to use it like this:

std::cout << myvehicle.toString() << std::endl;

Secondly, you can use + to concatenate std::string to each other, but you can't concatenate string literals and/or numbers like that. You calso can't do it with commas. You need to use a stringstream:
1
2
3
std::ostringstream ss;
ss << "Vehicle color = " << getVehicleColor() << /*etc...*/;
return ss.str();
Last edited on
in my main program i call the toString() using cout. Thanx for your help i will try it out.
Topic archived. No new replies allowed.