【Smart_Point】动态内存与智能指针实战:文本查询程序(设计set,map,智能指针的应用)
文章目录
- Cpp读入结构性数组
- 文本查询程序
- 文本查询程序本版1
Cpp读入结构性数组
#include<sstream>
#include<iostream>
#include<string>std::vector<cv::Point2f> point_calibartion_position;std::string filename = "C:/Users/Administrator/Desktop/singleplane/debug_output-042/reproject_points_on_image_plane.txt";std::ifstream infile(filename.c_str(),std::ios::in);std::string strline;while (getline(infile, strline)){std::cout << strline << std::endl;std:: istringstream is(strline);//std::string x, y;float x, y;is >> x >> y;//std::cout << x<<" "<<y<< std::endl;/*int index = 0;while (is >> s && index< 2 ){std::cout << s << std::endl;std::cout << s << std::endl;index++;}*/cv::Point2f single_point_pos;single_point_pos.x = x;single_point_pos.y = y;//std::cout << " x" << single_point_pos.x << " y" << single_point_pos.y << std::endl;point_calibartion_position.emplace_back(single_point_pos);}//infile.close;object_points_collection_.point_centers = point_calibartion_position;
文本查询程序
文本查询程序本版1
// The TextQuery and QueryResult classes use only capabilities that we have already covered.
// Without looking ahead, write your own versions of these classes.#include <string>#include <vector> #include <iostream> #include <fstream>
#include <memory>
#include <map> #include <set>
#include <sstream>
#include <algorithm>using std::string;
using std::vector;
using std::shared_ptr;class QueryResult;
class TextQuery {
public:using LineNo = vector<string>::size_type;TextQuery(std::ifstream&);QueryResult query(const string&) const;
private:shared_ptr<vector<string>> input;std::map<string, shared_ptr<std::set<LineNo>>> result;
};class QueryResult {
public:friend std::ostream& print(std::ostream&, const QueryResult&);
public:QueryResult(const string& s, shared_ptr<std::set<TextQuery::LineNo>> set, shared_ptr<vector<string>> v) : word(s), nos(set), input(v) { }
private:string word;shared_ptr<std::set<TextQuery::LineNo>> nos;shared_ptr<vector<string>> input;
};std::ostream& print(std::ostream&, const QueryResult&);TextQuery::TextQuery(std::ifstream& ifs) : input(new vector<string>)
{LineNo lineNo{ 0 };for (string line; std::getline(ifs, line); ++lineNo) {input->push_back(line);std::istringstream line_stream(line);for (string text, word; line_stream >> text; word.clear()) {// avoid read a word followed by punctuation(such as: word, )std::remove_copy_if(text.begin(), text.end(), std::back_inserter(word), ispunct);// use reference avoid count of shared_ptr add.auto& nos = result[word];if (!nos) nos.reset(new std::set<LineNo>);nos->insert(lineNo);}}
}QueryResult TextQuery::query(const string& str) const
{// use static just allocate once.static shared_ptr<std::set<LineNo>> nodata(new std::set<LineNo>);auto found = result.find(str);if (found == result.end()) return QueryResult(str, nodata, input);else return QueryResult(str, found->second, input);
}std::ostream& print(std::ostream& out, const QueryResult& qr)
{out << qr.word << " occurs " << qr.nos->size() << (qr.nos->size() > 1 ? " times" : " time") << std::endl;for (auto i : *qr.nos)out << "\t(line " << i + 1 << ") " << qr.input->at(i) << std::endl;return out;
}void runQueries(std::ifstream& infile)
{TextQuery tq(infile);while (true) {std::cout << "enter word to look for, or q to quit: ";string s;if (!(std::cin >> s) || s == "q") break;print(std::cout, tq.query(s)) << std::endl;}
}int main()
{std::ifstream file("../storyDataFile.txt");runQueries(file);
}
相关文章:

我眼中的DevOps(转)
过去一年以来,一批来自欧美的、不墨守陈规的系统管理员和开发人员一直在谈论一个新概念:DevOps。DevOps 就是开发(Development)和运维(Operations)这两个领域的合并。(如果没错的话,…
【阿圆实验】Consul HA 高可用方案
一、建立Consul Cluster环境 利用Consul提供的服务实现服务的注册与发现,需要建立Consul Cluster。在Consul方案中,每个提供服务的节点上都要部署和运行Consul的agent,所有运行Consul agent节点的集合构成Consul Cluster。Consul agent有两种…

【C++】拷贝,赋值与构造
拷贝,赋值与构造 文章目录拷贝,赋值与构造1. 拷贝构造函数/合成拷贝构造函数(copy constructor)2. 拷贝赋值运算符3. 析构函数1. 拷贝构造函数/合成拷贝构造函数(copy constructor) 1.1 定义:复…

Java 内存查看与分析
2019独角兽企业重金招聘Python工程师标准>>> 1:gc日志输出 在jvm启动参数中加入 -XX:PrintGC -XX:PrintGCDetails -XX:PrintGCTimestamps -XX:PrintGCApplicationStopedTime,jvm将会按照这些参数顺序输出gc概要信息,详细信息&…

玩转Vuejs--核心原理
一、摘要: Vuejs是一款前端MVVM框架,利用Vuejs、webpack以及周边一系列生态工具我们可以快速的构建起一个前端应用,网上对于Vue的分析大都是基于各个模块,理解起来不够顺畅,本文将从整个执行过程出发,讲一下…

【C++】拷贝控制与资源管理
1. 拷贝控制与资源管理 管理类外资源的类必须定义拷贝控制成员。如P447中所见,这种类需要通过析构函数来释放对象所分配的资源。一旦一个类需要析构函数,那么几乎可确定它也需要一个拷贝构造函数和一个拷贝赋值函数。 明确拷贝语义:可以定义…

leangoo V5.4.2版上线
本次更新增加了“卡片编辑面板内显示成员、截止日期、工作量”的功能。同时我们也进行了大量的功能优化,以下是此次更新详情: 1. 新增“卡片编辑面板内显示成员、截止日期、工作量”功能 本次更新后 ,您在卡片编辑面板内添加成员,…

差分边缘检测实现
#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/opencv.hpp> using namespace cv; // 图像差分操作 void diffOperation(const cv::Mat srcImage, cv::Mat& edgeXImage,cv::Mat& edgeYImage) {cv::Mat…

2.1:CGPROGRAM
文章著作权归作者所有。转载请联系作者,并在文中注明出处,给出原文链接。 本系列原更新于作者的github博客,这里给出链接。 前言 经过前面两个章节的铺垫,我们对渲染以及Unity Shaderlab相关的知识已经有了大概的认识,…

【OpenCV】OpenCV中积分图函数与应用
OpenCV中积分图函数与应用 参考资料 opencv 查找integral,目前网上大部分的资料来自于opencv https://docs.opencv.org/master/d7/d1b/group__imgproc__misc.html#gadeaf38d7701d7ad371278d663c50c77dhttps://blog.csdn.net/jia20003/article/details/52710751ht…

django学习笔记【003】创建第一个带有model的app
【1】python应用程序要连接mysql有多个驱动程序可供选择: 1、MySQLdb 这个只支持python2.x 所以在这里就不说了; 2、mysqlclient 下载地址 https://pypi.python.org/pypi/mysqlclient/1.3.9 3、MySQL Connector/python 这个是mysql官方主推的mysql驱…

图像非极大值抑制 Sobel 边缘实现
bool SobelVerEdge(cv::Mat srcImage, cv::Mat& resultImage) {CV_Assert(srcImage.channels() 1);srcImage.convertTo(srcImage, CV_32FC1);// 水平方向的 Sobel 算子cv::Mat sobelx (cv::Mat_<float>(3,3) << -0.125, 0, 0.125,-0.25, 0, 0.25,-0.125, 0, …

第四次作业 (日期和jieba库的运用)
设计题1: 设计一个本月份日历,输出格式如下: 要求: 1.初始化start_day,end_day两个日期 from datetime import datetime start_daydatetime(2019,4,1) end_daydatetime(2019,4,30) 其它时间数据生成要用datetime或date…

【C++】LINK类型错误分析记录
LINK类型错误 情况1: 根据生成路径,查找是否成功生成静态库/动态库,一般在./bin文件中。 情况2: 是否在CMakeLists中target_link_libraries中添加链接静态库操作 情况3: 是都存在类模板,需要实例化&a…

eBay宣布发布全新的购买和销售APIs
eBay最近宣布发布两款全新的购买和销售APIs。这些APIs旨在促进eBay产品在第三方应用程序中的更好集成。eBay于10月19日在他们的博客上发表了几篇文章,不仅详细介绍了这些全新的购买和销售APIs提供的功能,而且还详细地总结了他们公司从SOAP(简…

Sobel 边缘实现
#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <iostream> using namespace cv; // 非极大值抑制实现sobel竖直细化边缘 bool SobelVerEdge(cv::Mat srcImage, cv::…

vue下实现textarea类似密码框的功能之探索input输入框keyup,keydown,input事件的触发顺序...
项目中引入element的input框组件,触发事件必须要加上.native <el-input placeholder"请输入" type"textarea" v-model"valueText" keyup.native"keyUp(valueText,$event)" keydown.native"keyDown($event)" …

【C++】动态内存管理/move/以及移动构造与移动赋值运算符
文章目录1 .对象移动与右值引用 实际应用过程中遇到的问题及其解决方案c中临时变量不能作为非const的引用参数2. 动态内存管理类3. 对象移动与右值引用4. 移动构造与移动复制运算符1 .对象移动与右值引用 实际应用过程中遇到的问题及其解决方案 问题描述: bool Cr…

图像直接卷积 Sobel 边缘实现
bool sobelEdge(const cv::Mat& srcImage, cv::Mat& resultImage,uchar threshold) {CV_Assert(srcImage.channels() 1);// 初始化水平核因子Mat sobelx (Mat_<double>(3, 3) << 1, 0,-1, 2, 0, -2, 1, 0, -1);// 初始化垂直核因子Mat sobely (Mat_&…

JSON.parse解析特殊字符报错解决方案
2019独角兽企业重金招聘Python工程师标准>>> 具体案例: 页面点击”下一任务” 会去请求后台,这里出现的问题是有虚拟任务的时候。然后会返回一个map,也就是如下图中回调函数中的data。 当该map里存有以下字符的时候: \…

MySQL数据库字符集和整理
MySQL数据库字符集和整理(2009-11-20 22:23:37)mysql数据库 it 其实这个表在MySQL数据库中通过phpMyAdmin就能看到,icech只是把表格整理了一下方便大家使用,如果要更换数据库的字符集,心里有数。其中有三种utf8_general_ci、utf8_unicode_ci…

【SLAM后端】—— ceres优化相机位姿求解
求解结果如下: mat 初始化,eigenvalue初始化 Mat K ( Mat_<double> ( 3,3 ) << 520.9, 0, 325.1, 0, 521.0, 249.7, 0, 0, 1 );Eigen::Matrix<float,3,1> vd_3d;v_3d << 3, 2, 1;求解目标函数结构体构造与实例 struct CurveFi…

SPOJ 1811 LCS [后缀自动机]
题意: 求两个串的最大连续子串 一个串建SAM,另一个串在上面跑 注意如果走了Suffix Link,sum需要更新为t[u].val1 Suffix Link有点像失配吧,当前状态s走不了了就到Suffix Link指向的状态fa上去,fa是s的后缀所以是可行的…

图像卷积下非极大值抑制 Sobel 的实现
bool sobelOptaEdge(const cv::Mat& srcImage, cv::Mat& resultImage, int flag) {CV_Assert(srcImage.channels() 1);// 初始化sobel水平核因子cv::Mat sobelX (cv::Mat_<double>(3, 3) << 1, 0, -1,2, 0, -2, 1, 0, -1);// 初始化sebel垂直核因子cv::…

was unable to refresh its cache! status = Cannot execute request on any known server
出现这种错误是因为: Eureka服务注册中心也会将自己作为客户端来尝试注册它自己,所以我们需要禁用它的客户端注册行为。 在 yml中设置 eureka.client.register-with-eurekafalse eureka.client.fetch-registryfalse 但在服务端是要这是为false的,在客…

【C++】浅析析构函数(基类中)为什么要写成虚基类?
为什么有了虚析构函数,就能先调用子类的析构函数? class A {virtual ~A(){} };class B : A {virtual ~B(){} };A *p new B(); delete p; 唯一差别是,每个析构函数结束时会自动(隐含地)调上父类的析构函数࿰…

Roberts 边缘检测
#include <opencv2/opencv.hpp> // roberts算子实现 cv::Mat roberts(cv::Mat srcImage) {cv::Mat dstImage srcImage.clone();int nRows dstImage.rows;int nCols dstImage.cols;for (int i 0; i < nRows - 1; i){for (int j 0; j < nCols - 1; j){// 根据公…

vector、map删除当前记录
map<string, string> sMap; map<string, string>::iterator iter; for(iter sMap.begin();iter ! sMap.end();/* iter */) {sMap.erase(iter); }注意下列错误表达:1. for(iter sMap.begin();iter ! sMap.end(); iter ) {sMap.erase(iter); } 错误原因…

1-2 postman工具简介
postman提供了一个多窗口和多选项卡页面用于发送和接受请求,postman努力保持整洁和灵活,提供更多的空间,满足用户的需要。他很简单,能满足大部分接口的测试,性价比特别高。如图所示: 1.侧边栏 postman的侧边…

【C++】重载运算符(一)
1.1 重载运算符特点 重载运算符本质上是一次函数调用 除了operator() 运算符调用外,其他重载运算符不能含有默认参数。 当重载的运算符是成员函数时,this绑定到左侧运算对象。成员运算符函数(显式)的参数数量比运算对象少一个。…