wsprintf和%s的空字符串

时间:2015-06-15 15:53:18

标签: c++ string visual-studio-2013 printf

在VS13中我有这段代码:

wstring Result, EmptyString{ L"" };
if( EmptyString == L"" )
    Result = wstrprintf( L">%s<", L"" );
Result = wstrprintf( L">%s<", EmptyString );

第一个wsprintf正确返回><但第二个返回>☐+<,其中两个中间字符是随机wchars。我认为没有理由。

有替代方案吗?

1 个答案:

答案 0 :(得分:1)

%s需要一个C字符串:EmptyString.c_str(),而不是std::wstring个对象。