博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C实现读取文件的每一行 并标号
阅读量:4298 次
发布时间:2019-05-27

本文共 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/

你可能感兴趣的文章
ubuntu终端一次多条命令方法和区别
查看>>
python之偏函数
查看>>
vnpy学习_06回测结果可视化改进
查看>>
读书笔记_量化交易如何建立自己的算法交易01
查看>>
设计模式03_工厂
查看>>
设计模式04_抽象工厂
查看>>
设计模式05_单例
查看>>
设计模式06_原型
查看>>
设计模式07_建造者
查看>>
设计模式08_适配器
查看>>
设计模式09_代理模式
查看>>
设计模式10_桥接
查看>>
设计模式11_装饰器
查看>>
设计模式12_外观模式
查看>>
设计模式13_享元模式
查看>>
设计模式14_组合结构
查看>>
设计模式15_模板
查看>>
海龟交易法则01_玩风险的交易者
查看>>
CTA策略02_boll
查看>>
vnpy通过jqdatasdk初始化实时数据及历史数据下载
查看>>