读取txt数据

 

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <set>
#define MAXSIZE 100000
using namespace std;

set<int> OldRole12_31;
set<int> OldRole1_1;
set<int> OldRole1_2;

void main()
{
 FILE *fp12_31;
    FILE *fp1_1;
 FILE *fp1_2;

 if ( (fp12_31 = fopen( "d:\\OldRoleID12-31.txt", "r" )) == NULL )
  printf("ERROR!\n");
    if ( (fp1_1 = fopen( "d:\\OldRoleID1-1.txt", "r" )) == NULL )
  printf("ERROR!\n");
 if ( (fp1_2 = fopen( "d:\\OldRoleID1-2.txt", "r" )) == NULL )
  printf("ERROR!\n");
 
 int OldRoleID;
    int i=0;
    while ( !feof(fp12_31) && i!=MAXSIZE )
    {
        fscanf( fp12_31, "%d ", &OldRoleID );
  OldRole12_31.insert(OldRoleID);
        i++;
    }
 cout<<i<<endl;
 i=0;
 int j=0;
 while ( !feof(fp1_1) && i!=MAXSIZE)
    {
        fscanf( fp1_1, "%d ", &OldRoleID );
  if(OldRole12_31.find(OldRoleID)!=OldRole12_31.end())
  {
   OldRole1_1.insert(OldRoleID);
   j++;
  }
        i++;
    }
 cout<<j<<endl;
 i=0;
 j=0;
 while ( !feof(fp1_2) && i!=MAXSIZE)
    {
        fscanf( fp1_2, "%d ", &OldRoleID );
  if(OldRole1_1.find(OldRoleID)!=OldRole1_1.end())
  {
   j++;
  }
        i++;
    }
 cout<<j<<endl;
    fclose( fp1_1 );
    fclose( fp1_2 );
 fclose( fp12_31 );
    system("PAUSE");
}

 

posted @ 2012-01-03 20:33  byfei  阅读(118)  评论(0编辑  收藏  举报