VS2005 C++ str.Format 编译错误

 str.Format("5+3=%d",add(5,3));

error C2664: 'void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [7]' to 'const wchar_t *' c:/documents and settings/iamoyjj/my documents/visual studio 2005

改为,加L即可

str.Format(L"5+3=%d",add(5,3));

转载于:https://www.cnblogs.com/oyjj/archive/2007/07/08/2133029.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C++中并没有直接的`std::format`函数。引用中的代码展示了一个自定义的字符串格式化函数`str_format`,使用了`std::snprintf`函数来实现字符串格式化。这个函数可以接受一个格式化字符串和一系列参数,并返回一个格式化后的字符串。 引用展示了使用C++20引入的`std::format`函数进行字符串格式化的示例。`std::format`函数可以接受一个格式化字符串和一系列参数,并返回一个格式化后的字符串。这个函数是C++标准库中的新增功能,需要使用C++20或更新的编译器进行编译。 引用展示了使用`snprintf`函数进行字符串格式化的示例。这个函数可以接受一个格式化字符串和一系列参数,并将格式化后的结果存储在指定的字符数组中。在这个示例中,使用了`char`类型的字符数组`format_str`来存储格式化后的字符串。 综上所述,C++中可以使用自定义函数、`std::format`函数或`snprintf`函数来进行字符串格式化。具体使用哪种方法取决于编译器和使用的C++版本。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [C++ - std::string字符串格式化方法总结](https://blog.csdn.net/HW140701/article/details/127897839)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值