The problem is actually this part:
Code:
int max=100;
char arr[max];
You cannot use a non-const variable to create an array on the stack in this way. Try change it to:
Code:
const int max=100;
char arr[max];
Edit: Just tested the code with g++ w/o using const and it worked, probably because the compiler was smart enough to know that the size was defined beforehand. Your problem may actually be that you are using gcc to compile instead of g++. gcc is a C compiler, g++ is the C++ compiler.