問題描述
我試圖讓 to_string(NUMBER)
函數(shù)在我的 Ubuntu 計(jì)算機(jī)上工作數(shù)周,但它從來沒有在 QT 環(huán)境或其他任何地方工作過.我的代碼在 Mac osx 上運(yùn)行良好,但是當(dāng)我嘗試在 Ubuntu 中運(yùn)行它時,它抱怨 to_string
未在范圍內(nèi)聲明.對此的任何解決方案將不勝感激.我試圖更新 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 支持,您需要傳遞選項(xiàng) -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.
這篇關(guān)于to_string 未在范圍內(nèi)聲明的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!