錯誤:
error: ‘to_string’ was not declared in this scope
原因:
to_string是C++11引入的新功能,舊版本編譯器可能不支持它,所以要給編譯器加上“C++11”編譯支持
解決方案:
Linux下的GCC編譯器:在 g++ 命令行加入編譯選項 -std=c++11,例如:
g++ -o test test.cpp -std=c++11
CodeBlocks編譯器:工具欄打開Settings->Compiler,在這里勾選C++11標准即可。(參考鏈接)
Dev C++ 編譯器:在菜單欄點開Tools -> Compile Options,加上圈住的編譯指令即可讓編譯器支持c++11的標准。(參考鏈接)