I was trying the generate random numbers using mt19937
in c++ as shown in the code but I encounterd some weired behaviour.
#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;
}
}
When I run my code in "CLion", It runs and behaves as expected;however, when trying to run the code using the terminal, It doesn't compile and I recieve 'mt19937' was not declared in this scope
as an error message.
Here is the Error message screenshot
Update 1
I removed the #include <bits/stdc++. h>
from the code but the code still doesn't compile from terminal
Update 2
I have been using Mingw version which comes with Codeblocks so I uninstalled it and redownloaded Mingw from SourceForge. Surprisingly, the problem is now solved and I could run the code from the terminal.
Update 3
Now when I compile some program using the command g++ <name>.cpp
, a file named
a.exe
is created. I don't know why its name is always a.exe
regardless of the name of the original cpp file.
In order to name the .exe
file the same as the cpp file, I have to write
g++ <name>.cpp -o <name>
.
Can anyone help explain why the name is always a.cpp
??