how to initialize struct constructor with string

Hi dear All

any help would be so appreciated

i've got error error: expected primary-expression before '{' token

when I was attempting initialize my struct constructor with string

typedef struct Sensor_t{
  char    code[6];
  char   value[6];
                Sensor_t():code({"SXXX"}),value({"0000"}){}
};
Sensor_t income,outcome;

I remove and replace { and ( seperatley , but nothings happend, even with {'\0'}

It is not clear what you are trying to do. There is a definition of the structure, and some odd attempts to initialize data in that structure.

Separate the two, and do it properly. There should be a definition that has no attempt to initialize any struct members, and there should be code to initialize the members of an instance of the struct, once you have declared an instance.

Loose the typedef, you’re in C++.

In the IDE 1.0.x, or 1.5.6 and below, you will have to use the body of the constructor to assign the data:

struct Sensor_t{
  char    code[5];
  char   value[5];
  Sensor_t(){
    strcpy( code, "SXXX" );
    strcpy( value, "0000" );
  }
};
Sensor_t income,outcome;

If you have 1.5.7, you can enable C++11 and do this:

struct Sensor_t{
  char    code[6];
  char   value[6];
  Sensor_t():code{"SXXX"},value{"0000"}{}
};
Sensor_t income,outcome;