第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

c++怎么用fseek函數(shù)定位?

c++怎么用fseek函數(shù)定位?

尚方寶劍之說(shuō) 2019-03-06 11:07:44
#include<iostream>#include <fstream>#include <string>#include <string.h>using namespace std;void main(){//在文件中寫入學(xué)號(hào)和科目string number;string name;ofstream outstuf ; outstuf.open( "test.txt" , ios::app|ios::binary ) ; if ( !outstuf ) { cerr << "文件不存在" << endl ; abort(); }cin>>number;number=number+" ";outstuf.seekp(0,ios::end); //多這名,文件指針移到尾outstuf<<number.c_str();怎么用fseek()使得指針能指向到number后面,指向文件里面number的后面?
查看完整描述

3 回答

?
qq_笑_17

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超7個(gè)贊

int fseek(FILE *stream, long offset, int fromwhere);函數(shù)設(shè)置文件指針stream的位置。如果執(zhí)行成功,stream將指向以fromwhere(偏移起始位置:文件頭0(SEEK_SET),當(dāng)前位置1(SEEK_CUR),文件尾2(SEEK_END))為基準(zhǔn),偏移offset(指針偏移量)個(gè)字節(jié)的位置。如果執(zhí)行失敗(比如offset超過(guò)文件自身大小),則不改變stream指向的位置。
也就是寫成 fseek(outstuf,0,2);

查看完整回答
反對(duì) 回復(fù) 2019-03-26
?
繁星點(diǎn)點(diǎn)滴滴

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊

函數(shù)fseek使用指南

1.函數(shù)原型:

int fseek ( FILE * stream, long int offset, int origin );

2. 函數(shù)功能:

Sets the position indicator associated with the stream to a new position.

For streams open in binary mode, the new position is defined by adding offset to a reference position specified by origin.

For streams open in text mode, offset shall either be zero or a value returned by a previous call to ftell, and origin shall necessarily be SEEK_SET.

If the function is called with other values for these arguments, support
depends on the particular system and library implementation
(non-portable).

The end-of-file internal indicator of the stream is cleared after a successful call to this function, and all effects from previous calls to ungetc on this stream are dropped.

On streams open for update (read+write), a call to fseek allows to switch between reading and writing.

3. 函數(shù)參數(shù)

stream
Pointer to a FILE object that identifies the stream.

offset
Binary files: Number of bytes to offset from origin.
Text files: Either zero, or a value returned by ftell.

origin
Position used as reference for the offset. It is specified by one of the following constants defined in <cstdio> exclusively to be used as arguments for this function:

Constant
Reference position

SEEK_SET Beginning of file

SEEK_CUR Current position of the file pointer

SEEK_END End of file *

* Library implementations are allowed to not meaningfully support SEEK_END (therefore, code using it has no real standard portability).

4. 返回值

If successful, the function returns zero.
Otherwise, it returns non-zero value.
If a read or write error occurs, the error indicator (ferror) is set.

5. 例程

#include <stdio.h>

int main ()
{
FILE * pFile;
pFile = fopen ( "example.txt" , "wb" );
fputs ( "This is an apple." , pFile );
fseek ( pFile , 9 , SEEK_SET );
fputs ( " sam" , pFile );
fclose ( pFile );
return 0;
}
After this code is successfully executed, the file example.txt contains:
This is a sample



查看完整回答
反對(duì) 回復(fù) 2019-03-26
  • 3 回答
  • 0 關(guān)注
  • 1195 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)