In general, there is an array and you need to add elements to it. Question: how to do this?

static const char *payload_text[12]; payload_text[0] = "Date: Mon, 10 Nov 2018 21:54:29 +1100\r\n"; *payload_text[1] = "To: " TO_MAIL "\r\n"; *payload_text[2] = "From: " FROM_MAIL "\r\n"; *payload_text[3] = "Cc: " CC_MAIL "\r\n"; *payload_text[4] = "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@" "rfcpedant.example.org>\r\n"; *payload_text[5] = "Subject: SMTP example message\r\n"; *payload_text[6] = "\r\n"; *payload_text[7] = su; *payload_text[8] = "\r\n"; *payload_text[9] = "It could be a lot of lines, could be MIME encoded, whatever.\r\n"; *payload_text[10] = "Check RFC5322.\r\n"; *payload_text[11] = NULL; 
  • 2
    No, the size of the array cannot be changed. Instead of an array it is better to use std::vector . - HolyBlackCat
  • What does "add" mean? Your payload_text[0] = correctly written, but then some sort of nonsense went on. Why suddenly in *payload_text[1] = ... this * appeared? - AnT

1 answer 1

If we are talking about array initialization, then:

 static const char *payload_text[]={ "Date: Mon, 10 Nov 2018 21:54:29 +1100\r\n", "To: " TO_MAIL "\r\n", "From: " FROM_MAIL "\r\n", "Cc: " CC_MAIL "\r\n", "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@", "rfcpedant.example.org>\r\n", "Subject: SMTP example message\r\n", "\r\n", su, "\r\n", "It could be a lot of lines, could be MIME encoded, whatever.\r\n", "Check RFC5322.\r\n", nullptr};