C++ 无法获取<;随机>;图书馆工作
我很难让图书馆在macosx上工作。首先,我尝试编译以下代码,保存为RAND.CPP,取自C++网站C++ 无法获取<;随机>;图书馆工作,c++,macos,gcc,c++11,C++,Macos,Gcc,C++11,我很难让图书馆在macosx上工作。首先,我尝试编译以下代码,保存为RAND.CPP,取自C++网站 #include <iostream> #include <random> int main() { const int nrolls=10000; // number of experiments const int nstars=100; // maximum number of stars to distribute std
#include <iostream>
#include <random>
int main()
{
const int nrolls=10000; // number of experiments
const int nstars=100; // maximum number of stars to distribute
std::default_random_engine generator;
std::normal_distribution<double> distribution(5.0,2.0);
int p[10]={};
for (int i=0; i<nrolls; ++i) {
double number = distribution(generator);
if ((number>=0.0)&&(number<10.0)) ++p[int(number)];
}
std::cout << "normal_distribution (5.0,2.0):" << std::endl;
for (int i=0; i<10; ++i) {
std::cout << i << "-" << (i+1) << ": ";
std::cout << std::string(p[i]*nstars/nrolls,'*') << std::endl;
}
return 0;
}
四处搜索似乎表明问题出在编译器上,显然,因此该库仅对gcc11可用。我找到了一种使用macport包更新gcc的方法,如图所示,但我仍然不知道如何使用这个新编译器。运行g++rand.cpp-o rand
返回相同的错误,即使我使用sudo port select--set gcc gcc40
或sudo port select--set gcc mp-gcc46
更改编译器。我还尝试使用刚刚返回的g++-std=c++11 rand.cpp-o rand
cc1plus: error: unrecognized command line option "-std=c++11"
有人知道我做错了什么吗?用应该安装在mac或新版本GCC中的Clang++试试
- gcc42:我安装了这个版本,它无法工作,并且无法识别
和-std=c++0x
-std=c++11
- gcc49:使用
安装此软件时,会出现相同的错误,但brew
使其正常工作-std=c++11
- Clang++:工作起来很有魅力,甚至没有指定标准(它可能默认为c++11)
你做错了什么
您安装的版本没有
-std=c++11
选项,但它应该与-std=c++0x
或-std=gnu++0x
配合使用,这就是它所说的。尝试使用应安装在mac中的Clang++,或新版本的GCC
- gcc42:我安装了这个版本,它无法工作,并且无法识别
和-std=c++0x
-std=c++11
- gcc49:使用
安装此软件时,会出现相同的错误,但brew
使其正常工作-std=c++11
- Clang++:工作起来很有魅力,甚至没有指定标准(它可能默认为c++11)
你做错了什么
您安装的版本没有
-std=c++11
选项,但它应该与-std=c++0x
或-std=gnu++0x
一起工作,这就是它所说的。也尝试过,给出了cc1plus:error:无法识别的命令行选项“-std=c++11”
也尝试过,给出cc1plus:error:无法识别的命令行选项“-std=c++11”
-std=c++11已添加到gcc-4.7中。我认为-std=c++0x是在gcc-4.3中添加的。-std=c++11是在gcc-4.7中添加的。我认为gcc-4.3中添加了-std=c++0x。
cc1plus: error: unrecognized command line option "-std=c++11"