本文共 973 字,大约阅读时间需要 3 分钟。
FILE *readFile; fopen_s(&readFile, "file.txt", "r"); FILE *writeFile; fopen_s(&writeFile, "fileput.txt", "w"); char ch=0; int i = 1; ch = fgetc(readFile); if (ch != EOF&&ch != '\n') { fprintf(writeFile, "%03d", i++); } while (ch != EOF) { fputc(ch, writeFile); if (ch == '\n') { ch = fgetc(readFile); if (ch != EOF&&ch != '\n') { fprintf(writeFile, "%03d", i++); } } else{ ch = fgetc(readFile); } } fclose(readFile); fclose(writeFile);
C++的文件读取:
#include "stdafx.h"#include#include #include using namespace std;int main(int argc, char* argv[]){ ifstream readFile("ReadMe.txt"); ofstream writeFile("output.txt"); string s; int count = 1; while(getline(readFile,s)){ if(!s.empty()){ char c[4]; sprintf(c,"%03d",count++); writeFile<
转载地址:http://iinws.baihongyu.com/