编译器不知道std :: to_string? (C ++,即使在补丁之后)[重复]

问题描述 投票:-1回答:1

这个问题在这里已有答案:

停止 !在你将它标记为重复问题之前:问题是我的编译器不知道std :: to_string():我包含了字符串,经过一些研究后我发现它可能是一个MinGW(是的,我在Windows上)bug所以我尝试了这个补丁(http://tehsausage.com/mingw-to-string),但它不会工作:(你知道其他补丁或其他可能导致问题的事情吗?

error: 'to_string' is not a member of 'std'
a = b + std::to_string(12);

我的代码:

#include <iostream>
#include <string>

int main(){
  std::string a = "Hallo Welt.";
  std::string b("Hallo Welt.");
  std::string c(50,'i');

  a = b + c;
  a = b + std::to_string(12);
  return 0;
}
c++ c++11 compiler-errors tostring
1个回答
-3
投票

尝试重新创建该功能

#include <string>
#include <sstream>

template < typename T > std::string to_string( const T& n ) {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

#include <iostream>
using namespace std;

int main()
{
    cout << to_string(12) << endl;
    cout << to_string(456.2) << endl;
}

不要忘记包含sstream头文件

© www.soinside.com 2019 - 2024. All rights reserved.