读写文件
来源:互联网 发布:过敏源测试 知乎 编辑:程序博客网 时间:2024/06/04 18:15
#include <iostream>#include <fstream>#include <assert.h>#include <map>using namespace std;int stupidKmp(const char* dest, const char* src, int pos){ int i=pos; int j=0; while(dest[i+j] && src[j]) { if(dest[i+j]==src[j]) { j++; } else { i++; j=0; } } if(src[j]=='\0') { return i; } else { return -1; }}int main(){ map<int, int>mymap; char src[]="abc"; int H=1; ifstream readfile("./find.cpp",ios::in); ofstream write; write.open("./newfind.cpp"); string line; if(! readfile) { assert(false);//fail open } while(! readfile.eof()) { getline(readfile,line); write<<line.c_str()<<endl; int V=stupidKmp(line.c_str(),src,0); if(V != -1) { mymap.insert(make_pair(H,V)); } H++; } readfile.close(); write.close(); for(map<int ,int>::iterator iter=mymap.begin(); iter!=mymap.end(); iter++) { int first = iter->first; int second=iter->second; cout<< "row:"<<first<<" "<<"col:"<<second<<endl; } return 0;}find.cppaasssdafaabcdfadfaffsdfafefaefaabcsdfefasafefaseascabcasefweaerfawefasabefaeaeertawefabcasefaweaererawfaabcwf3aefe3faaabcwfweabc
1 0
- 文件读写、剪贴板读写
- 读写文件
- 文件读写
- 读写文件
- 读写文件
- 文件读写
- 读写文件
- 读写文件
- 读写文件
- 文件读写
- 文件读写
- 文件读写
- 文件读写
- 读写文件
- 文件读写
- 文件读写
- 文件读写
- 文件读写
- Trustzone安全内核SierraTEE将根文件系统从虚拟盘移至sd卡方案
- 前端编码规范-一般规范
- Kafka+Spark Streaming+Redis实时计算整合实践
- html中的meta标签
- #学志#我到底该会些什么?
- 读写文件
- 轮播图的基本原理
- C++调用PyRun_SimpleString时,参数字符串中有路径的处理
- math对象
- 无法获取焦点问题
- httpServletRequest.setCharacterEncoding 、httpServletResponse.setCharacterEncoding详解
- 图像卷积与滤波的一些知识点
- bzoj 2709: [Violet 1]迷宫花园 (最短路)
- 从零开始学习Vue(三)