-1

Hi there, I am new to C++ and I got this error. IntelliSense: no operator "+" matches these operands
The problematic line of code is:

cout << i << "\t" << temp->VehicleNo + "\n";

Link to picture showing context of error

https://i.stack.imgur.com/aTbwj.jpg

nrussell
  • 358
  • 1
  • 7
Lawrence Wong
  • 1,129
  • 4
  • 24
  • 40

1 Answers1

1

So, temp->VehicleNo is object of class Vehicle and this class has a member VehicleNo of type std::string. To display that string you need this code:

cout << i << "\t" << temp->VehicleNo.VehicleNo << "\n";

I would propose that you rename Node::VehicleNo to Node::Vehicle, so that in the code above the code would be temp->Vehicle.VehicleNo, which makes more sense.

Dialecticus
  • 16,400
  • 7
  • 43
  • 103
  • Hi there, VehicleNo is a string. So how do i resolve this problem? – Lawrence Wong Jan 10 '13 at 15:50
  • Hi there, Error 1 error C2039: 'c_str' : is not a member of 'Vehicle' 2 IntelliSense: class "Vehicle" has no member "c_str" How do i resolve this? – Lawrence Wong Jan 10 '13 at 15:56
  • Then VehicleNo is not `std::string`, but of type `Vehicle`, which is a class. We need to know what are the interesting members of this class. – Dialecticus Jan 10 '13 at 16:00
  • And please do not put an image of the class. Copy and paste relevant code into your original question. – Dialecticus Jan 10 '13 at 16:01
  • Under the vehicle class, I have string VehicleNo; declared inside the class. – Lawrence Wong Jan 10 '13 at 16:01
  • 1
    Try `temp->VehicleNo.VehicleNo` or `temp->VehicleNo.VehicleNo.c_str()`, or even `temp->VehicleNo->VehicleNo.c_str()`. It would be faster if you would provide enough information, so that we don't have to play the guessing game. – Dialecticus Jan 10 '13 at 16:06
  • You don't need `c_str()` to print a `std::string` to `std::cout`. – Blastfurnace Jan 10 '13 at 16:11