#include <iostream> #include <fstream> #include <set> #include <cstdlib> #include <ctime> using namespace std; inline void GenerateString(string & sTemp) { int m = rand()%10000; srand(clock()); char ch[10]; if (m/1000) sprintf(ch, "%d", m); else if (m/100) sprintf(ch, "0%d", m); else if (m/10) sprintf(ch, "00%d", m); else if (m) sprintf(ch, "000%d", m); sTemp += string(ch); } int main() { ofstream out; string sTemp; set<string> phone; out.open("hello.txt", ios::in|ios::out|ios::binary); srand(time(0)); while (phone.size() < 10000) { sTemp += "185"; GenerateString(sTemp); GenerateString(sTemp); phone.insert(sTemp); sTemp = ""; } set<string>::iterator itr; for (itr = phone.begin(); itr != phone.end(); itr++) { out<<*itr<<"\r\n"; } return 0; }