1

I made a class that gives main menu's sub menus and i want to write them to serial port but i can't make it happen.

#ifndef MENU_H
#define MENU_H

#include <iostream> //for std::string

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdlib.h>
#include <stdio.h>

#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif

#include "rs232.h"

#ifdef __cplusplus
}
#endif

#include "rs232.h"

using namespace std;

class Menu{

    Menu *upMenu;
    Menu *downMenu;
    Menu *rightMenu;
    string MenuName;
    public:
        Menu(); //default constructor
        ~Menu(); //default destructor
        void setUpMenu(Menu *);
        void setDownMenu(Menu *);
        void setRightMenu(Menu *);
        Menu* getUpMenu(Menu *);
        Menu* getDownMenu(Menu *);
        Menu* getRightMenu(Menu *);
        void printMenu(Menu *);
        void setMenuName(std::string);
        void getMenuName(Menu *);
};
#endif

This is my header file and below is where i try to write it to serial port so far.

 void Menu::getMenuName(Menu *menuName)
{     
    char *name = menuName->MenuName;
    RS232_cputs(17, name);

    cout<<menuName->MenuName<<endl;        
}

i can write menuName to console by cout bu cant write with RS232_cputs. It gave me this error => error: cannot convert ‘std::__cxx11::string {aka std::__cxx11::basic_string}’ to ‘char*’ in initialization char *name = menuName->MenuName;

And below is RS232_cputs func.

void RS232_cputs(int comport_number, const char *text)  /* sends a string to serial port */
{
  while(*text != 0)   RS232_SendByte(comport_number, *(text++));
}
Sukru
  • 128
  • 1
  • 1
  • 13
  • What is the type of `menuName->MenuName`? What is the type of `name`? Those two types are not compatible. Perhaps you should take a few steps back, [get a few good books to read](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282) and start over? – Some programmer dude Apr 03 '18 at 06:53
  • 1
    even if name assigned by string it returns same error as well – Sukru Apr 03 '18 at 07:05
  • If you change the type of `name` to `std::string`, then yes you would get the same error again if the `RS232_cputs` function expects a `char*` argument. Again, please read a book, or at least [a good `std::string` reference](http://en.cppreference.com/w/cpp/string/basic_string). – Some programmer dude Apr 03 '18 at 07:11
  • 1
    ok dont mad at me :) – Sukru Apr 03 '18 at 07:14

0 Answers0