Creates C string allocated using tryAllocate with copy of str. If str is null returns null.
tryAllocate is assumed to return properly aligned for To memory or null if allocation fails.
If allocation fails toCString will call $(COREREF exception, onOutOfMemoryError) which is expected to throw an $(COREREF exception, OutOfMemoryError).
t { import core.stdc.stdlib; import core.stdc.string; string str = "abc"; char* cstr = str.toCString!malloc(); scope(exit) free(cstr); assert(strlen(cstr) == 3
See Implementation
Creates C string allocated using tryAllocate with copy of str. If str is null returns null.
tryAllocate is assumed to return properly aligned for To memory or null if allocation fails.
If allocation fails toCString will call $(COREREF exception, onOutOfMemoryError) which is expected to throw an $(COREREF exception, OutOfMemoryError).