我试图让 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模板网!
编译器如何处理编译时分支?What do compilers do with compile-time branching?(编译器如何处理编译时分支?)
我可以使用 if (pointer) 而不是 if (pointer != NULL) 吗Can I use if (pointer) instead of if (pointer != NULL)?(我可以使用 if (pointer) 而不是 if (pointer != NULL) 吗?)
在 C/C++ 中检查空指针Checking for NULL pointer in C/C++(在 C/C++ 中检查空指针)
比较运算符的数学式链接-如“if((5<j<=1))&quMath-like chaining of the comparison operator - as in, quot;if ( (5lt;jlt;=1) )quot;(比较运算符的数学式链接-如“if((5<j<=1)))
“if constexpr()"之间的区别与“if()"Difference between quot;if constexpr()quot; Vs quot;if()quot;(“if constexpr()之间的区别与“if())
C++,'if' 表达式中的变量声明C++, variable declaration in #39;if#39; expression(C++,if 表达式中的变量声明)