I want to return a string from a function in C++ that is created from varying strings and an integer. I want to create a string in the form "ABCDFFFF00230000EFGH"
. "ABCD" is defined as a string in command[0]
, "0023"
is an integer defined by answer
, and "EFGH"
is defined as a string in command[4]
.
I have tried:
return "{0}FFFF{1}0000{2}".format(command[0], answer, command[4]);
But this gives an error:
member reference base type 'const char [18]' is not a structure or union
I have tried:
return (command[0], "FFFF", answer, "0000", command[4]);
But this only returns the value of command[4]
.
I have tried:
return (command[0] + "FFFF", answer + "0000" + command[4]);
I have also written this code in Python:
return "{0}FFFF{1}0000{2}".format(command[0], answer, command[4])
Which gave the right answer.