Let's say I have a string called garbage.
Whatever's in garbage, I want to make a char array out of it. Each element would be one char of the string.
So, code would be similar to:
const int arrSize = sizeof(garbage); //garbage is a string
char arr[arrSize] = {garbage};
But, this will give an error "cannot convert string to char in initialization".
What is the correct way to do this? I just want to feed the darn thing a string and make an array out of it.
std::string,sizeof(garbage)probably doesn't do what you think it does. It just gives you the size of astd::stringobject, which is a compile time constant that has no relation to the length of the string, which is a runtime value.arrSizecannot be used to specify the size ofarr, because it would no longer be a compile time constant.