簡體   English   中英

錯誤:名稱空間“ std”中沒有名為“ stod”的成員

[英]Error: no member named 'stod' in namespace 'std'

我正在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}'"]
   }
 ]
}

看起來您計算機上的Clang版本(偽裝為g++ ,在Mac上是常見設置)默認情況下仍在使用libstdc ++(GCC的C ++標准庫)。 OS X隨附的libstdc++版本很libstdc++ ,並且不支持C ++ 11( std::stod是C ++ 11的新增功能)。

-stdlib=libc++傳遞給編譯器,以使其改用Clang的標准庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM