gpt4 book ai didi

c++ - to_string(42) 不止一个实例匹配参数

转载 作者:行者123 更新时间:2023-11-30 01:59:26 25 4
gpt4 key购买 nike

与我使用 VS2010 的主题完全一样:

我有:

std::string s = std::to_string(42);

错误

Error   4   error C2668: 'std::to_string' : ambiguous call to overloaded function

如何修复?

最佳答案

Visual C++ 2010 只有三个用于 std::to_string 的重载,它们采用 long longunsigned long longlong双。该标准定义的不止于此,但 VC++ 2010 不支持它们。首选不从 int 文字 42 进行转换,因此调用不明确。相反,您可以使用不同类型的整数文字。例如:

std::string s = std::to_string(42LL);

关于c++ - to_string(42) 不止一个实例匹配参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16289572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com