在VC ++ 2005中向WCHAR *添加crlf

时间:2018-12-21 15:37:16

标签: c++ visual-c++ newline wchar

这是VC ++ 2005: 如何将WCHAR *“ firstText”和另一个WCHAR *“ secondText”附加到另一个WCHAR *“ thirdText”中,并且它们之间带有CRLF“ \ r \ n”?

WCHAR firstText [100] = L"First line";

WCHAR secondText [100] = L"Second line";

WCHAR thirdText [500] = L"";

我们非常感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您可以执行与非W字符串相同的操作,但是使用函数的宽字符串版本,例如(未试用)

int thirdTextMax = (sizeof(thirdText)/sizeof(thirdText[0]));
swprintf(thirdText, thirdTextMax, L"%s\r\n%s", firstText, secondText);

int firstTextLen = wcslen(firstText);
wcsncpy(thirdText, firstText, thirdTextMax);
wcsncpy(thirdText + firstTextLen, L"\r\n", thirdTextMax - firstTextLen);
wcsncpy(thirdText + firstTextLen + 2, secondText, thirdTextMax - firstTextLen - 2);

(这些函数也有_s版本,在溢出缓冲区时要格外小心,但我不记得它们是否在VC2005中。)