怎么把c语言编的程序的结果输入到一个文本文件中?

如题所述

第1个回答  2022-12-11

c语言编的程序的结果输入到一个文本文件中可以使用fprintf;

例:

#include<stdio.h>

main(){

FILE *fpt;

fpt = fopen("wendangming.txt","w");//打开文档,写入

fprintf(fpt,"Hello world");

fclose(fpt);

}

扩展资料

它打开一个文本文件,逐个字符地读取该文件

#include <iostream>

#include <fstream>

using namespace std;

int main()

{

fstream testByCharFile;

int num;

char c;

testByCharFile.open("6.5.cpp",ios::in);

while(!testByCharFile.eof())

{

testByCharFile >> c;

num++;

}

testByCharFile.close();

cout << num << endl;

}

相似回答
大家正在搜