网络服务器软件开发/中间件开发,关注ACE/ICE/boost

C++博客 首页 新随笔 联系 聚合 管理
  152 Posts :: 3 Stories :: 172 Comments :: 0 Trackbacks
#include   "stdafx.h"  
  #include   "string.h"  
  #include   "iostream.h"  
  #include   <stdio.h>  
  #include   <fstream.h>  
   
  int   main(int   argc,   char*   argv[])  
  {  
          fstream   f("e:\\test.txt",ios::in   |   ios::out   |   ios::trunc   |   ios::binary);  
  int   i;  
  cout<<"Enter   an   integer:"<<endl;  
  cin>>i;  
  f.write((char*)(&i),sizeof(i));  
  int   j=0;  
  f.seekg(0,ios::beg);  
  f.read((char*)(&j),sizeof(j));  
  cout<<j;  
  getchar();  
  return   0;  
  }  

得到文件长度
ifstream   in("readme.txt");  
  ...  
  streampos   pos   =   in.tellg();     //   save   current   position  
  in.seekg(0,   ios::end);  
  cout   <<   "file   length   ="   <<   in.tellg()   <<   endl;  
  in.seekg(pos);     //   restore   saved   position  
posted on 2007-04-29 18:14 true 阅读(817) 评论(0)  编辑 收藏 引用 所属分类: C++基础

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理