我尝试使用我的String添加一个char数组,当运行到strcat_s时,vs2013告诉我缓冲区太小,但我认为我确实给了足够的空间,即使我让temp.str更大,它仍然没用。那么这里发生了什么。顺便说一下,这是String类的友方函数。
String operator+(const char a[],const String & st)
{
String temp;
temp.len = std::strlen(a) + st.len+1;
temp.str = new char[temp.len];
strcpy_s(temp.str, std::strlen(a)+1, a);
strcat_s(temp.str, std::strlen(st.str)+1,st.str);
return temp;
}