c++ 实现对文件的读取和查找(写暂时没写)

该博客主要展示了如何使用C++实现对文件的读取和查找功能。通过定义一个名为CPmap的类,利用map容器存储键值对,并实现了文件的打开、读取、查找和显示内容的方法。
摘要由CSDN通过智能技术生成

CPmap.h
#pragma warning(disable: 4786)  // vc中去除STL使用带来的警告
#ifndef __CFGWRITER_H__ //防止重复调用头文件
#define __CFGWRITER_H__
#include "StdAfx.h"
#include <string>
#include <map>
#include <iterator>
#include <iostream>
using namespace std;
typedef map<string,string,less<string> > Mmap;//
typedef Mmap::iterator MIt; //
class CPmap  
{
public:
CPmap();
CPmap(string mpath);
    Mmap public_map;
//MIt It;
virtual ~CPmap();
    void show();
private:
string path;
bool do_open(const char* mpath);

};
#endif // !defined(AFX_PMAP_H__1A8D3C1B_6420_4A67_A5EB_C4CE390B2925__INCLUDED_) 
CPmap.cpp
// Pmap.cpp: implementation of the CPmap class.
//
//
#include "stdafx.h"
#include "Pmap.h"
#include "Write.h"
#include <fstream>
#include <vector>
#include <algorithm>   //use zhe for_each()
#define LEFT [ 
#define RIGHT ]
#define NOTES #
#define EQUAL =
#include <iostream>
using namespace std;
//
// Construction/Destruction
//
const char* const MIDDLE = "***";
CPmap::CPmap()
{
cout<<"don't find File"<<endl;
}
CPmap::CPmap(string mpath)
{
this->path=mpath;
if(do_open(mpath.c_str()))
cout<<"open the File: ok"<<endl;
else
cout<<"open the File:Error"<<endl;
}
CPmap::~CPmap()
{

}
bool CPmap::do_open(const char* mpath)
{
ifstream fin(mpath);
if (!fin.is_open())
return false;
vector<string> strvect;
vector<string>::iterator it;
string buffe

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值