【问题标题】:Error: no member named 'stod' in namespace 'std'错误:命名空间“std”中没有名为“stod”的成员
【发布时间】:2014-08-15 07:05:59
【问题描述】:

我在 Sublime Text 2 中运行代码。它显示错误:

item->open = std::stod(temp);

错误是:

error: no member named 'stod' in namespace 'std'
                item->open = std::stod(temp);

意识到sublime text 2不能运行c++11代码,所以看到了这个帖子:http://www.thefourtheye.in/2013/07/Compiling-Cpp-11-Programs-with-Sublime-Text-3.html

在 C++.sublime.build 中发布此代码:

{
 "cmd": ["g++", "-std=c++0x", "${file}", "-o", "${file_path}/${file_base_name}"],
 "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
 "working_dir": "${file_path}",
 "selector": "source.c, source.c++",
 "variants":
 [
   {
     "name": "Run",
     "cmd":["bash", "-c", "g++ -std=c++0x '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
   }
 ]
}

但错误仍然存​​在。不知道为什么。需要一些指导...

更新1:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.4.0
Thread model: posix

Update2:更改为 c++11。没有变化。

{
 "cmd": ["g++", "-std=c++11", "${file}", "-o", "${file_path}/${file_base_name}"],
 "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
 "working_dir": "${file_path}",
 "selector": "source.c, source.c++",
 "variants":
 [
   {
     "name": "Run",
     "cmd":["bash", "-c", "g++ -std=c++11 '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
   }
 ]
}

【问题讨论】:

  • 如果你的编译器/库不支持stod,你可以改用旧的C函数strtod
  • 更新了问题...
  • 只是检查:您是否包含了必要的头文件?
  • #include 对吗?我已经包含了它..
  • 对于较新版本的 gcc,正确的标志是 -std=c++11。看起来编译器是clang

标签: c++ sublimetext2


【解决方案1】:

看起来您计算机上的 Clang 版本(伪装成 g++,Mac 上的常见设置)默认仍使用 libstdc++(GCC 的 C++ 标准库)。 OS X 附带的libstdc++ 版本很古老,不支持C++11(而std::stod 是C++11 的补充)。

-stdlib=libc++ 传递给您的编译器,使其使用 Clang 的标准库。

【讨论】:

    猜你喜欢
    • 2021-03-04
    • 2013-06-09
    • 2017-02-13
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多