array initialization problem

Oct 19, 2009 at 12:30pm
hi everyone!


1
2
int num=6;
int s[num];


the compiler says:'s'unknown size.why this way cannot work.

thanks in advance.
Oct 19, 2009 at 12:36pm
The size of an array must be a constant value. If you want a resizable array use std::vector or std::deque
http://www.cplusplus.com/reference/stl/
Oct 19, 2009 at 1:50pm
thank you.
you usually give me the answer and more than this.
Oct 19, 2009 at 3:06pm
If you want to make a constant number, then you must specify it is const, e.g.

const int num = 6;
Oct 19, 2009 at 3:40pm
After i have a try ,i find the std::vector is very strong.(thanks also to firedraco
)
Topic archived. No new replies allowed.