You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS2022 C++20模式下std::format指针报错C3615如何解决?

解决VS2022 C++20下std::format指针格式化的C3615错误

问题原因

C++标准规定,std::format的:p格式说明符仅支持**void*类型**的指针参数。你传入的int*属于其他指针类型,VS2022的std::format实现会在编译期解析格式字符串时触发错误。

解决方法

将int*显式转换为void*后再传入std::format,同时补充函数的返回逻辑:

#include <format>
#include <string>

auto dump(int *p)
{
    std::string resultstring = std::format(" p points to address {:p}", static_cast<void*>(p));
    return resultstring;
}

另外,建议将VS2022更新至17.1及以上版本,旧版本的std::format实现存在部分兼容性bug,更新后可避免类似编译问题。

内容的提问来源于stack exchange,提问作者GeePokey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 01:01:06