写入文件中的特定位置 [英] Writing to specific position in a file

查看:133
本文介绍了写入文件中的特定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有

fstream output;
output.open(fname, ios::out | ios::trunc); //file
for (int i=0; i<flength; i++)
    output.put('1');

我要覆盖不同长度的数据到文件中的不同位置。数据是字符。

I want to overwrite different length of data to different locations in the file. Data is characters.

假设有 111111111111111111111111111111111 ,我想写

11   111111333111!!!!!!1    11441111


推荐答案

使用 seekp() 来设置文件流中的写入位置。

Use seekp() to set the writing position in the file stream.

这篇关于写入文件中的特定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆