Runtime error for CLang compiled program (Mac) reading double type with std::cin

妖精的绣舞 提交于 2019-12-06 01:19:58

std::basic_istream::operator>> calls std::num_get::get to extract the value from input. Until C++11, the behaviour of std::num_get::get was like that of scanf with the appropriate formatting string. C++11 onwards, std::num_get::get ends up calling strto* functions, which have a more flexible matching than the one based on scanf. In your example, 123[a-f] get interpreted as hex. Since all the input has been consumed by >>d, the >>s part of while(std::cin >> d >> s) leads to the parse failing.

user3789640

Ok, I found a solution to the problem in this question asked: CGAL: How can I successfully compile and link CGAL examples (on Mac OS X 10.9 Mavericks)

Compiling with clang++ as follows:

clang++ -o Main -std=c++11 -stdlib=libstdc++ Main.cpp

instead of:

clang++ -o Main -std=c++11 -stdlib=libc++ Main.cpp

solved the problem.

Anyway, as libc++ should be the preferred library to use with clang++ (as I just was told offline) I think it's time for a bug report.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!