I am attempting to create a character array of a fixed size on the stack (it does need to be stack allocated). the problem I am having is I cannot get the stack to allocate more than 8 bytes to the array:
#include <iostream>
using namespace std;
int main(){
char* str = new char[50];
cout << sizeof(str) << endl;
return 0;
}
prints
8
How do I allocate a fixed size array (in this case 50 bytes. but it may be any number) on the stack?
newdoes the opposite of allocating on the stack. What you need is a plain, ordinary array.char str[50];will do you fine. If you've got C++11,std::array<char, 50> str;would be better.sizeof()was measuring~ It is not what you think it is.