-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.cpp
More file actions
46 lines (42 loc) · 1.02 KB
/
generate.cpp
File metadata and controls
46 lines (42 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
if (argc < 4)
{
cout << "Please enter 3 parameters:\n";
cout << " Parameter 1: total count of numbers you want.\n";
cout << " Parameter 2: min value.\n";
cout << " Parameter 3: max value.\n";
cout << "Example: %generate 10000000 100000 999999\n";
exit(EXIT_SUCCESS);
}
for (int i=0; i<argc; i++)
{
cout << "argv["<<i<<"]:"<<argv[i]<< endl;
}
int COUNT = stoi(argv[1]);
int MIN = stoi(argv[2]);
int MAX = stoi(argv[3]);
ofstream fout;
fout.open("numbers.txt", ios::out | ios::trunc);
for (int i = 0; i < COUNT; i++)
{
fout << (rand() % ( MAX-MIN+1) + MIN) << endl;
}
fout.close();
return 0;
}
// basic file operations
// #include <iostream>
// #include <fstream>
// using namespace std;
//
// int main () {
// ofstream myfile;
// myfile.open ("example.txt");
// myfile << "Writing this to a file.\n";
// myfile.close();
// return 0;
// }