+ 1
Cpp program
How can i make a unique id for the single name on reservation system using c++ program
2 Réponses
+ 1
Please explain your question in a plain manner.
+ 1
By using a pseudo random number generator and a map container (really convenient for pairs and also it has some mechanism to check duplicate keys (IDs)) like this snippet.
#include <map>
#include <random>
#include <string>
//...
random_device rd;
mt19937 gen( rd() );
int main() {
string names[10] = {"boo","doo","koo","moo","joo","foo","loo","zoo","xoo","roo"};
map <int, string> rec;
uniform_int_distribution<> ID(1000, 9999);
for (auto i = 0; i < 10; ++i)
rec.insert( make_pair(ID(gen), names[i]) );
}
insert won't replace already added keys (IDs)