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

C++博客 首页 新随笔 联系 聚合 管理
  152 Posts :: 3 Stories :: 172 Comments :: 0 Trackbacks
#include <iostream>
#include <fstream>
using namespace std;

#ifdef WIN32
#define TEST_FILE   "c:\\tmp\\test.txt"
#else
#define TEST_FILE   "/tmp/test.txt"
#endif

void test()
{
    {
        //fstream sfs;
        //sfs.open(TEST_FILE, ios_base::out);
        fstream sfs(TEST_FILE, ios_base::out);
       
        char buf[] = "1234567890";
        sfs.write(buf, sizeof(buf));

        sfs.close();
    }

    {
        int len;
        char* buf;

        //fstream sfs;
        //sfs.open(TEST_FILE);
        fstream sfs(TEST_FILE);
       
        sfs.seekg (0, ios::end);
        len = sfs.tellg();
        sfs.seekg (0, ios::beg);

        buf = new char[len];
        sfs.read(buf, len);
        cout << buf << endl;
        delete []buf;

        sfs.close();
    }
}

int main(int argc, char* argv[])
{  
    test();
    return 0;
}
posted on 2007-05-27 18:57 true 阅读(469) 评论(0)  编辑 收藏 引用 所属分类: C++基础

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