c++ - 当我使用 mt19937 在 C++ 中生成随机数时遇到了一个问题
问题描述
我正在尝试使用 c++ 生成随机数mt19937
,如代码所示,但我遇到了一些奇怪的行为。
#include <iostream>
#include <random>
#include <chrono>
using namespace std;
int main() {
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
int n = rng() % 10 + 2;
cout << n << endl;
for (int i = 0; i < n; i++) {
int x = rng() % 10 + 1;
int y = rng() % 10 + 1;
cout << x << " " << y << " " << endl;
}
}
当我在“CLion”中运行我的代码时,它会运行并按预期运行;但是,当尝试使用终端运行代码时,它不会编译,我会收到'mt19937' was not declared in this scope
一条错误消息。
这是错误消息屏幕截图
更新 1
我#include <bits/stdc++. h>
从代码中删除了,但代码仍然不能从终端编译
更新 2
我一直在使用Codeblocks附带的Mingw版本,所以我卸载了它并从SourceForge 重新下载了 Mingw 。令人惊讶的是,问题现在解决了,我可以从终端运行代码。
更新 3
现在,当我使用命令编译一些程序时g++ <name>.cpp
,会创建一个名为的文件
a.exe
。我不知道为什么它的名字总是a.exe
不管原始cpp文件的名字。为了将文件命名.exe
为与 cpp 文件相同的名称,我必须编写
g++ <name>.cpp -o <name>
. 任何人都可以帮助解释为什么这个名字总是a.cpp
?
解决方案
推荐阅读
- r - 即使在 {r, message=FALSE} 时,R Markdown Knitted PDF doc 也会继续显示消息
- vb.net - 文本框搜索重音字符问题?
- c# - LINQ Group 通过显示不正确的结果
- python - twitter 搜索 api - 只选择文本而不是用户
- reactjs - 在 GatsbyJS 中将自定义 React 组件导入 Markdown
- ssh - 当SSH在本地机器上终止时保持jupyter实验室笔记本运行?
- r - R中的$m是什么意思?
- javascript - 如何在 Angular 9 中显示文件的内容?
- laravel - PHP 单元测试 Laravel
- amazon-web-services - SSH 进入 EC2 实例超时