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.
Related Posts:
- Is there a function to copy an array in C/C++?
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- Double pointer array in c++
- Warning: comparison of distinct pointer types
- What is a segmentation fault?
- How many spaces for tab character(\t)?
- How to dynamically allocate arrays in C++
- What does (~0L) mean?
- What is the difference between float and double?
- How do I find the length of an array?
- What is the effect of extern “C” in C++?
- What exactly is the difference between “pass by reference” in C and in C++?
- When to use extern “C” in simple words? [duplicate]
- Floating point exception( core dump
- Return array in a function
- Mutex example / tutorial? [closed]
- What does “dereferencing” a pointer mean?
- What is an unsigned char?
- What does “dereferencing” a pointer mean?
- Passing an array by reference
- Convert char to int in C and C++
- Why use conio.h?
- How to track down a “double free or corruption” error
- Convert an int to ASCII character
- How to track down a “double free or corruption” error
- Why unsigned int 0xFFFFFFFF is equal to int -1?
- What is the significance of return 0 in C and C++?
- How to go from fopen to fopen_s
- What is use of c_str function In c++
- lvalue required as left operand of assignment – Array
- What is the difference between const int*, const int * const, and int const *?
- How to print pthread_t
- What is the difference between const int*, const int * const, and int const *?
- What is the printf format specifier for bool?
- Reverse Contents in Array
- Should I learn C before learning C++?
- warning: ISO C++ forbids variable length array
- c++ array – expression must have a constant value
- Visual Studio debugger error: Unable to start program Specified file cannot be found
- Passing a 2D array to a C++ function
- Fatal error: iostream: No such file or directory in compiling C program using GCC
- Convert Python program to C/C++ code?
- Is “argv[0] = name-of-executable” an accepted standard or just a common convention?
- Examples of good gotos in C or C++
- How to convert C++ Code to C
- How to add element to C++ array?
- warning: control reaches end of non-void function [-Wreturn-type]
- C++: Expression must have a constant value when declaring array inside function
- gcc/g++: “No such file or directory”
- splitting a string into an array in C++ without using vector
- How to use glOrtho() in OpenGL?
- Printing an array in C++?
- Delete 2D array C++
- Best C/C++ Network Library
- How do malloc() and free() work?
- How to run valgrind with basic c example?
- Typedef function pointer?
- “…redeclared as different kind of symbol”?
- How to add element to C++ array?
- Debug vs Release in CMake
- How can I get the list of files in a directory using C or C++?
- Debug vs Release in CMake
- How can I get the list of files in a directory using C or C++?
- What does “Permission denied” “Id returned 1 exit status” mean?
- extended initializer lists only available with
- Multi-character constant warnings
- Creation of Dynamic Array of Dynamic Objects in C++
- how to initialize an empty integer array in c++
- What is the C equivalent to the C++ cin statement?
- Static linking vs dynamic linking
- Check if C++ Array is Null
- C++ Initializing a Global Array
- Is there a replacement for unistd.h for Windows (Visual C)?
- Comparing the values of char arrays in C++
- How to project a point onto a plane in 3D?
- C: using strtol endptr is never NULL, cannot check if value is integer only?
- How can I assign an array from an initializer list?
- Why use pointers?
- How do I return a char array from a function?
- What’s the difference between * and & in C?
- creating an array of structs in c++
- How to read lines of text from file and put them into an array
- Why can’t we pass arrays to function by value?
- How to write log base(2) in c/c++
- How to memset char array with null terminating character?
- What is the source of the data for the ProgramFiles, ProgramW6432Dir, ProgramFilesDir (x86), CommonProgramFiles environment variables?
- creating dynamic array of string c++
- C++ Array of pointers: delete or delete []?
- Is there a standard sign function (signum, sgn) in C/C++?
- too many initializers for ‘int [0]’ c++
- C++ 2d char array to string
- cc1.exe System Error – libwinpthread-1.dll missing – But it isn’t
- Two decimal places using printf( )
- Using cin to input a single letter into a char
- Is C++ Array passed by reference or by pointer?
- Is there a way to compile C++ to C Code?
- Linker error: “linker input file unused because linking not done”, undefined reference to a function in that file
- The tilde operator in C
- Array of Linked Lists C++
- C++ float array initialization