c – 错误:没有匹配函数来调用’to_string(std :: basic_string
发布时间:2020-12-16 09:57:11 所属栏目:百科 来源:网络整理
导读:即使在模板中我可以有任何类型,函数to_string也不适用于基本字符串: 例如: std::string str("my string");my_class(str); 使用此仿函数定义: templateclass valuetypevoid operator()(valuetype value){ ... private_string_field = std::to_string(value
即使在模板中我可以有任何类型,函数to_string也不适用于基本字符串:
例如: std::string str("my string"); my_class(str); 使用此仿函数定义: template<class valuetype> void operator()(valuetype value) { ... private_string_field = std::to_string(value); 不起作用.这是错误:
什么是避免它的最佳方法. 我提前请求避免链接到不相关的问题只是因为一些常见的关键字. 解决方法std::to_string 仅适用于基本数字类型.
如果您需要更通用的功能, #include <boost/lexical_cast.hpp> ... private_string_field = boost::lexical_cast<std::string>(value); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |