未在范围中声明to_string [英] to_string not declared in scope

查看:188
本文介绍了未在范围中声明to_string的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的Ubuntu计算机上使 to_string(NUMBER)函数工作数周,但它从未在QT环境或其他任何地方工作。我的代码可以在Mac osx上完美运行,但是当我尝试在Ubuntu上运行它时,它抱怨未在范围中声明 to_string 。任何解决方案将不胜感激。我曾尝试更新gcc编译器,但没有解决问题。请帮忙。

I am trying to make the to_string(NUMBER) function work in my Ubuntu computer for weeks but it never ever works in the QT environment or anywhere else. My code works perfectly on my Mac osx, but when I try running it in Ubuntu it complains that to_string is not declared in scope. Any solutions to this would be greatly appreciated. I have tried to update the gcc compiler but it didn't fix the problem. Please help.

我正在使用QT Creator 4.8.1,并且正在使用C ++和最新版本的Ubuntu。

I am using QT Creator 4.8.1 and I am using C++ and latest version of Ubuntu.

int Bint::operator*(int temp){
    Bint b(to_string(temp));
    return ((*this)*b);
}

我错过了QMAKE_CXXFLAGS + = -std = c ++ 0x专业档案。

I was missing the QMAKE_CXXFLAGS += -std=c++0x in the pro file.

推荐答案

它对您不起作用可能有不同的原因:也许您需要用<$ c来限定名称$ c> std :: ,或者您可能不支持C ++ 11。

There could be different reasons why it doesn't work for you: perhaps you need to qualify the name with std::, or perhaps you do not have C++11 support.

只要您拥有C ++,此方法就可以使用11个支持:

This works, provided you have C++11 support:

#include <string>

int main()
{
  std::string s = std::to_string(42);
}

要通过g ++或clang启用C ++ 11支持,您需要传递选项 -std = c ++ 0x 。您还可以在这些编译器的较新版本上使用 -std = c ++ 11

To enable C++11 support with g++ or clang, you need to pass the option -std=c++0x. You can also use -std=c++11 on the newer versions of those compilers.

这篇关于未在范围中声明to_string的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆