lakesh lakesh - 1 month ago 5
C++ Question

Error: no member named 'stod' in namespace 'std'

I am running a code in Sublime Text 2. It shows me an error:

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


The error is:

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


Realised that sublime text 2 can't run c++11 code, so saw this post:http://www.thefourtheye.in/2013/07/Compiling-Cpp-11-Programs-with-Sublime-Text-3.html

Posted this code in 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}'"]
}
]
}


But the error still exist. Not sure why. Need some guidance...

Update1:

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: Changed to c++11. No change.

{
"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}'"]
}
]
}

Answer

Looks like the version of Clang (masquerading as g++, a common setup on Mac) on your computer is still using libstdc++ (GCC's C++ standard library) by default. The version of libstdc++ that comes with OS X is ancient, and doesn't have C++11 support (and std::stod is a C++11 addition).

Pass -stdlib=libc++ to your compiler to make it use Clang's standard library instead.

Comments