C++ array assign error: invalid array assignment

Because you can’t assign to arrays — they’re not modifiable l-values. Use strcpy:

#include <string>

struct myStructure
{
    char message[4096];
};

int main()
{
    std::string myStr = "hello"; // I need to create {'h', 'e', 'l', 'l', 'o'}
    myStructure mStr;
    strcpy(mStr.message, myStr.c_str());
    return 0;
}

And you’re also writing off the end of your array, as Kedar already pointed out.

Leave a Comment