c++ stl bitset 位图操作

/*
 * bitset.cpp
 *
 *  Created on: 2013-1-1
 *      Author: Administrator
 */


#include
#include
#include
#include
#include
#include


using namespace std;


#define MAX_SIZE 1000000
void write_number() {
FILE * fh = fopen("./data/digit.txt", "a");
if (fh) {
srand((int) time(0));
for (int i = 0; i < 10; i++) {
int num = rand()%MAX_SIZE;
fprintf(fh, "%d\n", num);
}
fclose(fh);
}


}


void read_number() {
FILE * fh = fopen("./data/digit.txt", "r");
if (fh) {
int num;
while (EOF != fscanf(fh, "%d", &num)) {
printf("%d\n", num);
}
fclose(fh);
}


}
int main() {


cout< write_number();
read_number();
bitset bitmap;
bitmap.reset();


FILE * fh = fopen("./data/digit.txt", "r");
if (fh) {
int num;
while (EOF != fscanf(fh, "%d", &num)) {
cout< bitmap[num] = 1;
}
fclose(fh);
}
for (int i = 0; i < MAX_SIZE; i++) {


if (bitmap[i] == 1) {
cout << i << ",";
}
}


return 0;
}

你可能感兴趣的:(c/c++)