【发布时间】: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