gpt4 book ai didi

c++11 to_string 与 code::blocks -std=c++11 flag already selected

转载 作者:可可西里 更新时间:2023-11-01 16:42:34 25 4
gpt4 key购买 nike

这是我正在尝试编译的代码,是从某个地方的另一个论坛获得的。

// to_string example

#include <iostream> // std::cout

#include <string> // std::string, std::to_string


int main ()

{

std::string pi = "pi is " + std::to_string(3.1415926);

std::string perfect = std::to_string(1+2+4+7+14) + " is a perfect number";

std::cout << pi << '\n';

std::cout << perfect << '\n';

return 0;

}

我收到错误:'to_string' 不是 'std' 的成员

我在其他论坛上读到选择标志“让 g++ 遵循 c++11 ISO 语言标准 [-std=c++11]”,我已经这样做了,但它仍然不起作用。

任何帮助将不胜感激

我正在使用 GNU GCC 编译器和代码:: block 12.11

最佳答案

自 GCC 4.8 起,MinGW-w64 添加了对必要功能的支持,因此请确保您至少使用 MinGW-w64 的 4.8 版 GCC。

你可以从 here 得到一个, 虽然 Code::Blocks 应该带有 TDM GCC如果是最新的工具链应该可以使用(因为在撰写本文时它是 GCC 4.8.1)。

关于c++11 to_string 与 code::blocks -std=c++11 flag already selected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19893922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com