cpp ofstream ifstreram binary 文档读写

include

include

include

include

include <sys/stat.h>

include

void test_copy_binary(std::string src,std::string dst){

    std::ofstream ostrm(dst,std::ios::binary);
    std::ifstream istrm(src,std::ios::binary);
    if (!istrm.is_open() )
    {
        std::cout<<"failed to open: "<<src<<std::endl;
        return ;
    }
    if (!ostrm.is_open())
    {
        std::cout<<"failed to open: "<<dst<<std::endl;
        return ;
    }
    {
        char buf[1];
        while(1){

            istrm.read(buf,1);
            if(istrm.eof())
            {
                break;
            }
            ostrm.write(buf,1);
            istrm.seekg(1024);
        }
        istrm.close();
        ostrm.close();
    }
}

posted @ 2022-10-18 17:23  simp00  阅读(26)  评论(0编辑  收藏  举报