What happens in your case is that you are trying to initialize a c-style array with another c-style array.
C-style arrays can't be initialized in this manner nor can they be copied using a regular copy assignment.
To copy it using the copy assignment would require looping through and copying one element at a time and actually assigning a size to the second array.
There are two more practical approaches for your problem.
Either use std::array<>
or another container type, instead of a char array, or use memcpy
For the former approach you'll just have to replace your arrays to type std::array<>
and then you can initialize or copy with the regular copy assignment as you like.
For the latter approach you can use memcpy()
to copy the memoryblock from the first c-style array to the other. Like this:
Read these reference pages on memcpy:
http://www.cplusplus.com/reference/cstring/memcpy
https://en.cppreference.com/w/cpp/string/byte/memcpy
{
/* ... */
char new_tab[1024] = {0};
std::memcpy(new_tab, prev_tab, sizeof(char)*1024);
std::cout << "The value after copy is: " << new_tab << std::endl;
/* ... */
}
Edit:
As your intent with this was not clear, but lets assume it is an assignment and you have to convert to an array and then copy the array to another array.
In that case read this for reference:
https://en.cppreference.com/w/cpp/string/byte/strncpy
http://www.cplusplus.com/reference/cstring/strncpy/
And then keep things as you had them but just change your char Array[] = {tab2};
To:
{
/* ... */
char new_tab[1024];
// Copies 1024 characters from prev_tab to new_tab
std::strncpy(new_tab, prev_tab, 1024);
/* ... */
}
Note: Also edited and added some reference links