Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有定义为指针+大小的字节数组:
size_t size; // size in bytes void *data; // NOT zero-terminated string
如何从中构造(最好是零拷贝)“字符串”?
这假设data指向不可变内存:
data
string s = (cast(immutable(char)*)data)[0..size];
如果不是,则 achar[]会比字符串更合适,或者您可以使用.idup.
char[]
.idup