在磁盘中有一文件名为file.exe,当程序提示我输入文件名时我输入了file.exe,为什么总是打不开呢

题目:对于某一给定的时间段,用户登陆到某个计算机系统。在这段时间里,每当他们登陆到这个系统,他们的用户ID就被

自动记录到一个日志文件中。因为同一个用户可能登陆很多次,所以这个日志文件可能包含很多重复的用户ID。我们希望编写一个没有重复的用户ID的列表,并在这个列表中记录每个ID登陆了很多次

 

 

#include<iostream>
#include<fstream>
#include<string>
#include<vector>
using namespace std;
int main()
{

 int search(string & aUserId,vector<string> & userId);
 string filename;
 cout<<"please enter the file name :";
 cin>>filename;
    ifstream instream(filename.data());
 if(!instream.is_open())
 {
  cout<<"Unable to ople the file:/n";
  exit(-1);
 }
 vector<string> userId;
 vector<int> loginCount;
 string aUserId;
 for( ; ; )
 {
  getline(instream,aUserId);
  if(instream.eof())break;
  int i;
  if((i=search(aUserId,userId))>=userId.size())
  {
   userId.push_back(aUserId);
   loginCount.push_back(1);
  }
  else
  {
   loginCount[i]++;
  }
 }
 for(int j=0;j<userId.size();j++)
 {
  cout<<"the userId is :"<<userId[j]<<endl;
  cout<<"the loginCount is :"<<loginCount[j]<<endl;
 }
return 0;
}
int search(string & aUserId,vector<string> & userId)
{
 int i=0;
 for( ; ; )
 {
  if(i>=userId.size()||userId[i]==aUserId)break;
  i++;
 }
 return i;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值