日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

c++freopen函数_使用示例的C语言中的freopen()函数

發(fā)布時間:2025/3/11 c/c++ 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c++freopen函数_使用示例的C语言中的freopen()函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

c++freopen函數

C語言中的freopen()函數 (freopen() function in C)

Prototype:

原型:

FILE* freopen(const char *str, const char *mode, FILE *stream);

Parameters:

參數:

const char *str, const char *mode, FILE *stream

Return type: FILE*

返回類型: FILE *

Use of function:

使用功能:

The prototype of the function freopen() is:

函數freopen()的原型為:

FILE* freopen(const char *str, const char *mode, FILE *stream);

The freopen() function opens the existing stream into another file. The end-of-file and error flag is cleared in this process. The file named as str with its operation mode, opens it into the file stream named as stream. The freopen() function acts similar to the fopen() function. In the following output we can see the work of the function.

freopen()函數將現有流打開到另一個文件中。 文件結束和錯誤標志在此過程中被清除。 以其操作模式命名為str的文件將其打開到名為stream的文件流中 。 freopen()函數的作用類似于fopen()函數。 在以下輸出中,我們可以看到該函數的工作。

C中的freopen()示例 (freopen() example in C)

#include <stdio.h> #include <stdlib.h>int main(){//Initialize the file pointerFILE *f,*fp;//Take a array of characters char ch[100];//Create the file for write operationf=fopen("includehelp.txt","w");printf("Enter five strings\n");for(int i=0;i<4;i++){//take the strings from the usersscanf("%[^\n]",&ch);//write back to the filefputs(ch,f);//every time take a new line for the new entry string //except for last entry.Otherwise print the last line twicefputs("\n",f);//clear the stdin stream buffer//if we don't write this then after taking string fflush(stdin);}//%[^\n] is waiting for the '\n' or white space//take the strings from the usersscanf("%[^\n]",&ch);fputs(ch,f);//reopen the file for read operationfp=freopen("includehelp.txt","r",fp); printf("File content is--\n");printf("\n...............print the strings..............\n\n");while(!feof(fp)){//takes the first 100 character in the character array fgets(ch,100,fp);//and print the stringsprintf("%s",ch);}//close the filesfclose(fp);fclose(f);return 0; }

Output

輸出量

翻譯自: https://www.includehelp.com/c-programs/freopen-function-in-c-language-with-example.aspx

c++freopen函數

總結

以上是生活随笔為你收集整理的c++freopen函数_使用示例的C语言中的freopen()函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。