Can't assign string to char * like the docs say

Trass3r mrmocool at gmx.de
Wed May 13 12:56:17 PDT 2009


Doctor J schrieb:
> 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*"
> 

Of course this doesn't work.
Try char* p = str.ptr;


More information about the Digitalmars-d-learn mailing list