dev c++使用PHYSFS的例子


//! 使用PHYSFS的例子
/*
    dev c++
    核动力机器人
    2009.08.16
*/

#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include "physfs.h"

using namespace std;

int main(int argc, char *argv[])
{   
    //! 初始化PHYSFS
    bool flag = PHYSFS_init(0);
    std::cout<<"初始化physfs: "<<flag<<std::endl;
   
    std::cout<<PHYSFS_addToSearchPath("C://Documents and Settings//Administrator//My Documents//dev", false)<<std::endl;
    char** buf = PHYSFS_getSearchPath();

    if(buf == 0)
    { 
        std::cout<<"get search path failed."<<std::endl;  
    }
    else
    {  
        std::vector<std::string> dirs;
        for(char** i = buf; *i != 0; ++i)
        {
            dirs.push_back(*i);
        }
        std::cout<<"dirs is: "<<dirs.size()<<std::endl; 
        PHYSFS_freeList(buf);  
        std::copy(dirs.begin(),dirs.end(),std::ostream_iterator<std::string>(cout,"/n"));
    }

    //! 获取目录分隔符
    std:cout<<PHYSFS_getDirSeparator()<<std::endl;
   
    //! 获取基本目录路径
    std::cout<<PHYSFS_getBaseDir()<<endl;
   
    //std::cout<<PHYSFS_getLastError()<<std::endl;
   
    //! 获取基本程序路径
    cout<<"get basic user dir is: "<<PHYSFS_getUserDir()<<endl;
   
    //! 获取写路径 
    //cout<<"write dir is: "<<PHYSFS_getWriteDir()<<endl;
 
    //! 设置写路径
    //cout<<"set write path is: "<<PHYSFS_setWriteDir("C://Documents and Settings//Administrator//My Documents//dev")<<endl;
   
    //std::cout<<PHYSFS_getLastError()<<std::endl;
   
    PHYSFS_file* file;
  
    file = PHYSFS_openRead("1.txt");
    if(file==NULL)
        cout<<"load file failed"<<endl;
    else
        cout<<"open file is: ok"<<endl;
       
    //! 获取文件长度
    int size = PHYSFS_fileLength(file);
    std::cout<<size<<endl;
   
    //! 获取当前file ptr
    std::cout<<PHYSFS_fileLength(file)<<endl; 
   
    char *ptr = new char[size];
    std::cout<<PHYSFS_read(file, ptr, 10, 1)<<endl;
    cout<<ptr<<endl;  
    delete []ptr;
 
    PHYSFS_close(file);
 
    std::cout<<PHYSFS_getLastError()<<std::endl;
   
    //! 终止PHYSFS
    PHYSFS_deinit();
    system("PAUSE");
    return EXIT_SUCCESS;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值