Issues with to_string

Issues with to_string

本文关键字:string to with Issues      更新时间:2023-10-16

我尝试这样的编译时会出现以下错误。 c date.cc -std = C 11

" date.cc:41:40:错误:'to_string'不是'std'" "的成员

这是代码:

if ( _month < 1 || _month > 12 )
{
throw domain_error{"Month " + std::to_string(_month) + " doesn't exist!"};
}

如果我删除std ::我得到: "'to_string'在此范围中没有声明'

我的版本是:GCC版本5.3.0(GCC)

有什么建议?

std::to_string在标题<string>中定义。

您需要添加#include <string>

http://en.cppreference.com/w/cpp/string/basic_string/to_string