Wednesday, 2 October 2013

how do you concatinate strings and integer in c++

how do you concatinate strings and integer in c++

I am trying to concatinate string and integer as follows:
#include "Truck.h"
#include <string>
#include <iostream>
using namespace std;
Truck::Truck (string n, string m, int y)
{
name = n;
model = m;
year = y;
miles = 0;
}
string Truck :: toString()
{
string truckString = "Manufacturer's Name: " + name + ", Model Name:
" + model + ", Model Year: " + year ", Miles: " + miles;
return truckString;
}
I am getting this error:
error: invalid operands to binary expression ('basic_string<char,
std::char_traits<char>, std::allocator<char> >'
and 'int')
string truckString = "Manufacturer's Name: " + name + ", Model
Name: " + model + ", Model Year: " + year ", Miles...
any ideas what I might be doing wrong? I am new to c++

No comments:

Post a Comment