Printing to Controller

I was trying to work on printing to the V5 controller and I was encountering problems with strings. I put some code below.

class printingclass
{
  private:
  std::string partone;
  std::string parttwo;

  
  void findscreenpart ()
  {
    if(screen == 1)
    {
      partone = "Socks";
    }
    if(screen == 2)
    {
      partone = "Jacket";
    }
    if(screen == 3)
    {
      partone = "Shorts";
    }
    if(screen == 4)
    {
      partone = "Pants";
    }
  }

    void findcolorpart ()
  {
    if(colorfocus == 1)
    {
      parttwo = "Blue";
    }
    if(colorfocus == 2)
    {
      parttwo = "Yellow";
    }
    if(colorfocus == 3)
    {
      parttwo = "Red";
    }
    if(colorfocus == 4)
    {
      parttwo = "Nothing";
    }
  }

  public:

  void printbasicmenu ()
  {
    findcolorpart();
    findscreenpart();
    controller2.Screen.clearScreen();
    controller2.Screen.setCursor(1,1);
    controller2.Screen.print(partone + " : " + parttwo);
  }

};

Unfortunately, VexCode does not like the part at the end

controller2.Screen.print(partone + " : " + parttwo);

Will the V5 controller only print if you are using some sort of integer? I have seen some threads with stuff similar to

controller2.Screen.print("Result = %d", 5);

But that wasn’t exactly what I was hoping for. It seems to be what VexCode wants from what I see in the console about the error.

I have seen Java and partially lua use this format.
You could append strings which would allow you to add more information to it, then printing said string:
http://www.cplusplus.com/reference/string/string/append/

If you could give the error message that would help to identify the problem.

Most likely controller2.Screen.print takes in a const char * not an std::string. The string class does have a solution for this so try this code…

std::string combinedString;

combinedString = partone + " : " + parttwo;

controller2.Screen.print(combinedString.c_str());
3 Likes

Likely the better way of solving the problem^