Chinaunix首页 | 论坛 | 博客
  • 博客访问: 157663
  • 博文数量: 76
  • 博客积分: 1513
  • 博客等级: 上尉
  • 技术积分: 755
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-25 15:15
文章分类

全部博文(76)

文章存档

2012年(2)

2011年(74)

我的朋友

分类: C/C++

2011-11-25 21:12:45

  1. #include<iostream>

  2. #include<String>

  3. #include<fstream>

  4. #include<stdlib.h>

  5. using namespace std;

  6.  

  7. int main()

  8. {

  9.     ifstream fin;

  10.     string str,str2;

  11.     cout<<"input the filename:"<<endl;

  12.     cin>>str;

  13.     fin.open(str.c_str(),ifstream::binary|ifstream::in);

  14.     

  15.     char ch;

  16.     cout<<"input the char to be counted!"<<endl;

  17.     cin>>ch;

  18.     int cnt=0;

  19.     while(!fin.eof())

  20.     {

  21.                      if(fin.get()==ch) cnt++;

  22.                      

  23.     }

  24.     cout<<cnt<<endl;

  25.     cout<<"Total number of""<"is:"<<cnt<<endl;

  26.    ofstream fout;

  27.     cout<<"input the filename to save the value:"<<endl;

  28.     cin>>str2;

  29.     fout.open(str2.c_str(),ofstream::binary|ofstream::out);

  30.     char* ch1;

  31.     itoa(cnt,ch1,10);

  32.     fout.write((char*)ch1,1);

  33.     fout.close();

  34.     fin.close();

  35.     return 0;
  36. }
阅读(490) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~