It can be simple but I m new about c++
In char arrays we can let the compiler to count number of characters in the string like
char myarray[]="stringvar";
its ok, but if i change the code as below,the compiler gives error
string myvar = "stringvar";
char myarray[] =myvar;
error: initializer fails to determine size of myarray
Why is that?
You can do this:
In this case, the data which
myarraypoints to, lives as long as the lifetime ofmyvar.However, if you want a mutable string or, a string which may last longer (or shorter) than the lifetime of
myvar, then you’ve to allocate memory yourself as: