Can't assign string to char * like the docs say
Doctor J
nobody at nowhere.com
Wed May 13 11:28:46 PDT 2009
Taken straight from http://www.digitalmars.com/d/1.0/arrays.html, this doesn't compile:
void main()
{
string str = "abc";
char* p = str; // pointer to 1st element
}
"Error: cannot implicitly convert expression (str) of type char[] to char*"
I agree it shouldn't compile; I guess I'm asking why the docs say it does.
While I'm at it, what's up with the very first strings example:
char[] str;
char[] str1 = "abc";
str[0] = 'b'; // error, "abc" is read only, may crash
Should that just be:
char[] str = "abc";
str[0] = 'b'; // error, "abc" is read only, may crash
More information about the Digitalmars-d-learn
mailing list