我试图让 to_string(NUMBER)
函数在我的 Ubuntu 计算机上工作数周,但它从来没有在 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);
}
我在 pro 文件中遗漏了 QMAKE_CXXFLAGS += -std=c++0x.
I was missing the QMAKE_CXXFLAGS += -std=c++0x in the pro file.
它对您不起作用的原因可能有多种:也许您需要使用 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 未在范围内声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!