C实现读取文件的每一行 并标号
来源:互联网 发布:mac里的airdrop 编辑:程序博客网 时间:2024/05/04 15:47
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<iostream>#include<fstream>#include<string>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<<c; } writeFile<<s<<endl; } writeFile.close(); readFile.close(); return 0;}
0 0
- C实现读取文件的每一行 并标号
- 读取文件的每一行内容并输出 的shell脚本实现
- shell:读取文件的每一行内容并输出
- shell:读取文件的每一行内容并输出
- shell:读取文件的每一行内容并输出
- shell:读取文件的每一行内容并输出
- shell:读取文件的每一行内容并输出
- shell:读取文件的每一行内容并输出
- shell:读取文件的每一行内容并输出
- shell:读取文件的每一行内容并输出
- 读取文件每一行
- 反向读取文件的每一行
- shell读取文件每一行的方式
- shell读取文件的每一行
- shell读取文件的每一行
- shell读取文件的每一行
- shell读取文件的每一行
- shell读取文件的每一行
- #每天学习一个新的php函数 (1) substr()
- ulimit命令
- Linux命令大全
- 2015年04月29日学习情况及以后10天计划
- endl 与 buffer
- C实现读取文件的每一行 并标号
- 攻略nginx
- poj2777Count Color
- 评估期已过。有关如何升级的测试版软件的信息,请访问http://www.microsoft.com/sql/howtobuy
- 交换排序之冒泡排序
- awk 调用变量
- HDU4499Cannon
- Validate Binary Search Tree
- IOS --- 单例模式