<分区>
我本来是一名Java程序员,我非常喜欢语法,尤其是String
对象。使用 C++,我尝试重新创建 Java 具有的 toUpperCase()
方法。唯一的问题是它总是返回一个具有空/NULL 字符数组的 String
对象。
String String::toUpperCase()
{
char *a = new char[this->length + 1];
memset(a, 0, this->capacity + 1);
memcpy(a, this->characters, this->length);
for (int i = 0; i < strlen(this->characters); i++)
{
toupper(a[i]);
}
return *new String(a);
}