C++ Primer学习笔记第六章tquery.cpp程序的剖析

VFIO框架源码分析(二十二)- IOMMUFD 的脏页跟踪与 Dirty Bits 读取 在虚拟化热迁移(Live Migration)的场景中,脏页追踪(Dirty Page Tracking)是最具挑战性的环节之一。它的核心任务是实时捕获设备(DMA)对内存的写操作,以便 VMM(如 QEMU)知道哪些内存页需要被重新传输到目标主机。在强耦合与粗粒度:脏页追踪是绑定在 Container 上的。这意味着,如果一个 Container 内有多个设备,哪怕只有一个设备在写内存,脏页追踪也会影响 Container 内的所有设备。软件模拟开销大。 阅读详情

/*

tquery.c

我用的编译器是gnu c++ 和 vc2003,为了此程序能够执行需做以下的修改:

1           tquery.c -> tquery.cpp

2           <iostream.h> -> <iostream>, <fstream.h> -> <fstream> , <stddef.h> -><cstddef>

3           增加 #include <iterator> 和 using namespace std;

4           删除 allocator 和它前面的“,”号,注意在要在>>之间留一个空格,因为编译器不是神仙,它会把>>当成操作符

5           删除250行的diff_type,对于现在的编译器,它已经过时了

6           对于执行gnu c++ 执行:g++  -o  tquery.ext  tquery.cpp 〔ENTER〕

7           对于vc2003 执行:cl  tquery.cpp 〔ENTER〕

*/

#include <algorithm> //提供泛型算法的接口,比如copy

#include <string>

#include <vector>

#include <utility> //pair的接口

#include <map>

#include <set>

 

#include <iostream>

#include <fstream>

 

#include <cstddef> //定义了NULL,size_t等类型

#include <ctype.h> //为了大小写字母的处理

 

#include <iterator> //因为运用了ostream_iterator模板对象所以这是必须的,而原程序没有包含

 

using namespace std; //为了方便,所以显式指定名字空间是标准名字空间

 

typedef pair<short,short>        location;  //这样做完全是为了方便理解,没有太大的意义

typedef vector<location>  loc;

typedef vector<string>    text;

typedef pair<text*,loc*>         text_loc; //完整的类型是pair< vector<string>*, vector< pair<short,short> >* >

//如果是我写的话,肯定会把location,loc,text,text_loc排在一列,李破门先生为何要这么做?我想大概是个人的喜好问

//题,这样做有它的好处,就是不会把定义相互混淆

 

class TextQuery {

public:

       TextQuery() { memset( this, 0, sizeof( TextQuery )); } /*我们知道memset是一个C语言的函数,这句把this指向的那块内存大小为sizeof(TextQuery)个单元初值设置为0,我对这个构造函数的理解是:因为此类的成员函数操纵的是一些string,所以把内存做这样的解释是为了提高string处理的效率,因为memset虽然返回的是void*指针,但是却被编译器解释成char*指针*/

 

       static void filter_elements( string felems ) { filt_elems = felems; }//静态成员函数说:“我是为了filt_elems而存在”

 

       void query_text();

       void display_map_text();

       void display_text_locations();

       void doit() {

               retrieve_text();

               separate_words();

               filter_text();

               suffix_text();

               strip_caps();

               build_word_map();

       }

 

private:

       void retrieve_text();

       void separate_words();

       void filter_text();

       void strip_caps();

       void suffix_text();

       void suffix_s( string& );

       void build_word_map();

 

private:

       vector<string>            *lines_of_text;

       text_loc                               *text_locations;

       map<string,loc*,less<string> > *word_map;

       static string                          filt_elems;  //我是属于类的,所以我属于所有对象,但我与它们一点关系也没有,即//使它们不存在,我也存在, 而且我是唯一的,不会每个对象都有一份,所以我节省空间,注意不要在类里初始化我,//为什么?去问Bjarne Stroustrup,那是俺爹

};

 

string TextQuery::filt_elems( "/",.;:!?)(///" );

 

int main()

{

       TextQuery tq;

       tq.doit();

       tq.query_text();

        tq.display_map_text();

       return 0;

}

//获得文本

/*我先大体的叙述一下retrieve_text函数是做什么和怎么做的,此函数读取输入的文本文件中的每一行,一行一行地记录其内容,为什么这么说呢,你想想看: 它把输入的文本文件一行一行的读出来,看做string,用push_back放在了vector中,简言之vector中的0号元素就是text文件的第一行,以此类推。
  
它是如何做的呢?首先它构建了一个ifstream对象,这个对象的本身代表输入文本文件自己,接着getline登场,注意getline有两个一个是为流提供的getline,一个是在<string>中为string提供的getline,此处用的是后者。getline顾名思义,就是得到文件的一行,其实那倒也不一定,取决于getline的第三个参数,默认的参数就是“/n",“/n"意味着getline就是名副其实的get line,接下来vector的push_back粉墨登场,它把从getline获取的每一行做为string放进vector容器中,此时vector的大小会自动的加1。最终的结果就是,输入的文本被放在了一个string vector容器中,而前面的类的私有成员:vector<string> *lines_of_text就是指向这个容器的指针,抢答:(*lines_of_text)[ 0 ]代表什么?欧,是的,它代表输入文本第一行,如果你要求严格一点,它代表输入文本第一行的一个拷贝。其它的部分很简单,就此略过。*/

void

TextQuery::

retrieve_text()

{

       string file_name;

      

       cout << "please enter file name: ";

       cin  >> file_name;

 

       ifstream infile( file_name.c_str(), ios::in ); //infile是一个ifstream对象,当然ifstream是一个由typedef定义的模板类,它锁定了char类型做为参数,构造函数需要一个const char*,ios::in的意义是首先ios是一个锁定char类型的流模板,而in是告诉流要为输入而打开一个文件

       if ( !infile ) {

              cerr << "oops! unable to open file "

                   << file_name << " -- bailing out!/n";

              exit( -1 );

       }

       else cout << "/n";

 

       lines_of_text = new vector<string>;

        string textline;

 

        while ( getline( infile, textline, '/n' ))

              lines_of_text->push_back( textline ); //把一行放入lines_of_text所指向的string vector中,vector自加1

}

 

//分离出单个的词并捕获其位置(?行,?列)

/*

问题1:如何分离出单个词?

答:根据词间的空格

问题2:如何迭代?

       答:for循环迭代行,while循环寻找每一行的空格

*/

void

TextQuery::

separate_words()

{

        vector<string>   *words     = new vector<string>;

       vector<location> *locations = new vector<location>;

 

        for ( short line_pos = 0; line_pos < lines_of_text->size(); line_pos++ ) /*对于书中给出的输入文本文件text_file->size()应该是6,因为string vector就是6行所以对于for循环就是for(short line_pos = 0;line_pos < 6; line_pos++),共循环6次来迭代每一行*/

        {

              short  word_pos = 0;

                string textline = (*lines_of_text)[ line_pos ];

 

                string::size_type eol = textline.length();

                string::size_type pos = 0, prev_pos = 0;

 

                while (( pos = textline.find_first_of( ' ', pos )) != string::npos ) /*例如:对于第一行 :

Alice Emma has long flowing red hair. Her Daddy says eol: 52 pos: 5 line: 0 word: 0 substring: Alice 意思是说,数到52,第一行结束,数到第5时出现个空格(记住Lippman先生说过要从0开始数),是第0行,此时标记出第一个词,位置是0,内容是Alice,再把Alice放进words中,words是一个string vector,想想为什么要放进vector中,因为要给单独的词一个代号比如0号,1号,2号.......*/

                {

                        words->push_back( textline.substr( prev_pos, pos - prev_pos ));

                     locations->push_back( make_pair( line_pos, word_pos )); /*locations是一个pair vector,执行完此句locations就变成{word[0] =(0, 0)......}了*/

 

                        word_pos++; pos++; prev_pos = pos;

                }

 

                words->push_back( textline.substr( prev_pos, pos - prev_pos ));

              locations->push_back( make_pair( line_pos, word_pos ));

        }

      

        text_locations = new text_loc( words, locations );

/*

text_loc完整的类型是:

pair< vector<string>*, vector< pair<short,short> >* >,

就像这样:(word[0],(0,0)[0]),(word[1],  (0,1)[1]) 。。。。。。

*/

 

//滤去标点符号

void

TextQuery::

filter_text()

{

       if ( filt_elems.empty() )

            return;

 

       vector<string> *words = text_locations->first;

 

       vector<string>::iterator iter = words->begin();

       vector<string>::iterator iter_end = words->end();

 

       while ( iter != iter_end )

       {

                string::size_type pos = 0;

                while (( pos = (*iter).find_first_of( filt_elems, pos )) != string::npos ) //find_first_of如果没有找到匹配的项会返回string::npos所以可以用string::npos做为标志

                       (*iter).erase(pos,1);

              iter++;

       }

}

 

//处理后缀

void

TextQuery::

suffix_text()

{

        vector<string> *words = text_locations->first;

 

        vector<string>::iterator iter = words->begin();

        vector<string>::iterator iter_end = words->end();

 

        while ( iter != iter_end )

        {

              // if 3 or less characters, let it be

              if ( (*iter).size() <= 3 ) { iter++; continue; }

              if ( (*iter)[ (*iter).size()-1 ] == 's' )

                     suffix_s( *iter );

 

              // additional suffix handling goes here ...

 

                iter++;

        }

}

 

//处理后缀的辅助函数

void

TextQuery::

suffix_s( string &word )

{

        string::size_type spos = 0;

        string::size_type pos3 = word.size()-3;

 

        // "ous", "ss", "is", "ius"

        string suffixes( "oussisius" );

 

        if ( ! word.compare( pos3, 3, suffixes, spos, 3 ) ||

             ! word.compare( pos3, 3, suffixes, spos+6, 3 ) ||

             ! word.compare( pos3+1, 2, suffixes, spos+2, 2 ) ||

             ! word.compare( pos3+1, 2, suffixes, spos+4, 2 ))

                return;

 

        string ies( "ies" );

        if ( ! word.compare( pos3, 3, ies ))

        {

             word.replace( pos3, 3, 1, 'y' );

             return;

        }

 

        string ses( "ses" );

        if ( ! word.compare( pos3, 3, ses ))

        {

             word.erase( pos3+1, 2 );

             return;

        }

 

        // erase ending 's'

        word.erase( pos3+2 );

 

        // watch out for "'s"

        if ( word[ pos3+1 ] == '/'' )

             word.erase( pos3+1 );

}

 

//处理大写字母

void

TextQuery::

strip_caps()

{

        vector<string> *words = text_locations->first;

 

        vector<string>::iterator iter = words->begin();

        vector<string>::iterator iter_end = words->end();

 

       string caps( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" );

 

        while ( iter != iter_end ) {

                string::size_type pos = 0;

                while (( pos = (*iter).find_first_of( caps, pos )) != string::npos )

                       (*iter)[ pos ] = tolower( (*iter)[pos] );

                ++iter;

        }

}

 

 

void

TextQuery::

build_word_map()

{

     word_map = new map< string, loc*, less<string> >;

 

     typedef map<string,loc*,less<string> >::value_type value_type;

     typedef set<string,less<string> >::difference_type diff_type;

 

     set<string,less<string> > exclusion_set;

 

     ifstream infile( "exclusion_set" );

     if ( !infile )

     {

          static string default_excluded_words[25] = {

            "the","and","but","that","then","are","been",

            "can","can't","cannot","could","did","for",

            "had","have","him","his","her","its","into",

            "were","which","when","with","would"

          };

 

          cerr << "warning! unable to open word exclusion file! -- "

               << "using default set/n";

 

          copy( default_excluded_words, default_excluded_words+25, inserter( exclusion_set, exclusion_set.begin() ));

     }

     else {

          istream_iterator< string, diff_type > input_set( infile ), eos;

          copy( input_set, eos, inserter( exclusion_set, exclusion_set.begin() ));

     }

 

     // iterate through the the words, entering the key/pair

 

     vector<string,allocator>   *text_words = text_locations->first;

     vector<location,allocator> *text_locs  = text_locations->second;

 

     register int elem_cnt = text_words->size();

     for ( int ix = 0; ix < elem_cnt; ++ix )

         {

                string textword = ( *text_words )[ ix ];

 

                // exclusion strategies

                // less than 3 character or in exclusion set

                if ( textword.size() < 3 ||

                     exclusion_set.count( textword ))

                        continue;

 

                if ( ! word_map->count((*text_words)[ix] ))

                {  // not present, add it:

                   loc *ploc = new vector<location,allocator>;

                   ploc->push_back( (*text_locs)[ix] );

                   word_map->insert( value_type( (*text_words)[ix], ploc ));

                }

                else (*word_map)[(*text_words)[ix]]->push_back( (*text_locs)[ix] );

         }

}

 

//处理用户的查询,此函数像是shell

void

TextQuery::

query_text()

{

       string query_text;

   

       do {

           cout << "enter a word against which to search the text./n"

               << "to quit, enter a single character ==>  ";

          cin  >> query_text;

 

          if ( query_text.size() < 2 ) break;

 

           string caps( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" );

           string::size_type pos = 0;

           while (( pos = query_text.find_first_of( caps, pos )) != string::npos )

                    query_text[ pos ] = tolower( query_text[pos] );

 

           // if we index into map, query_text is entered, if absent

           // not at all what we should wish for ...

 

          if ( !word_map->count( query_text )) {

              cout << "/nSorry. There are no entries for "

                   << query_text << "./n/n";

              continue;

           }

 

          loc *ploc = (*word_map)[ query_text ];

 

           set<short,less<short>,allocator> occurrence_lines; 

           loc::iterator liter = ploc->begin(), liter_end = ploc->end();

 

            while ( liter != liter_end ) {

                  occurrence_lines.insert(occurrence_lines.end(), (*liter).first);

                    ++liter;

            }

 

           register int size = occurrence_lines.size();

           cout << "/n" << query_text

               << " occurs " << size

               << (size == 1 ? " time:" : " times:")

               << "/n/n";

 

           set<short,less<short>,allocator>::iterator it=occurrence_lines.begin();

           for ( ; it != occurrence_lines.end(); ++it ) {

                int line = *it;

 

                cout << "/t( line "

                     // don't confound user with text lines starting at 0 ...

                    << line + 1 << " ) "      

                     << (*lines_of_text)[line] << endl;

           }

 

           cout << endl;

        }

       while ( ! query_text.empty() );

        cout << "Ok, bye!/n";

}

 

void

TextQuery::

display_map_text()

{

        typedef map<string,loc*,less<string>,allocator> map_text;

        map_text::iterator iter = word_map->begin(), iter_end = word_map->end();

 

        while ( iter != iter_end ) {

                cout << "word: " << (*iter).first << " (";

 

                int           loc_cnt = 0;

                loc          *text_locs = (*iter).second;

                loc::iterator liter     = text_locs->begin(),

                              liter_end = text_locs->end();

 

                while ( liter != liter_end )

                {

                        if ( loc_cnt )

                             cout << ",";

                        else ++loc_cnt;

 

                        cout << "(" << (*liter).first

                             << "," << (*liter).second << ")";

 

                        ++liter;

                }

 

                cout << ")/n";

                ++iter;

        }

 

        cout << endl;

}

 

void

TextQuery::

display_text_locations()

{

        vector<string,allocator>   *text_words     = text_locations->first;

        vector<location,allocator> *text_locs      = text_locations->second;

 

        register int elem_cnt = text_words->size();

 

        if ( elem_cnt != text_locs->size() )

        {

             cerr << "oops! internal error: word and position vectors "

                  << "are of unequal size/n"

                  << "words: " << elem_cnt << " "

                  << "locs: "  << text_locs->size()

                  << " -- bailing out!/n";

             exit( -2 );

        }

 

        for ( int ix = 0; ix < elem_cnt; ix++ )

        {

                cout << "word: " << (*text_words)[ ix ] << "/t"

                     << "location: ("

                     << (*text_locs)[ix].first  << ","

                     << (*text_locs)[ix].second << ")"

                     << "/n";

        }

 

        cout << endl;

}

 

/*

sample input text:

------------------

 

Alice Emma has long flowing red hair. Her Daddy says

when the wind blows through her hair, it looks almost alive,

like a fiery bird in flight. A beautiful fiery bird, he tells her,

magical but untamed. "Daddy, shush, there is no such thing,"

she tells him, at the same time wanting him to tell her more.

Shyly, she asks, "I mean, Daddy, is there?"

 

---------------------

sample query session:

---------------------

 

please enter file name: alice_emma

 

warning! unable to open word exclusion file! -- using default set

 

enter a word against which to search the text.

to quit, enter a single character ==>  alice

 

alice occurs 1 time:

 

        ( line 1 ) Alice Emma has long flowing red hair. Her Daddy says

 

enter a word against which to search the text.

to quit, enter a single character ==>  daddy

 

daddy occurs 3 times:

 

        ( line 1 ) Alice Emma has long flowing red hair. Her Daddy says

        ( line 4 ) magical but untamed. "Daddy, shush, there is no such thing,"

        ( line 6 ) Shyly, she asks, "I mean, Daddy, is there?"

 

enter a word against which to search the text.

to quit, enter a single character ==>  phoenix

 

Sorry. There are no entries for phoenix.

 

enter a word against which to search the text.

to quit, enter a single character ==>  .

Ok, bye!

 

----------------------------------------------------------

sample text map after: (a) stripping out punctuation,

(b) eliminating semantically neutral words such as `the`,

(c) suffixing, so that fixes and fix become fix, and

(d) removal of capitalization

-----------------------------------------------------------

 

word: alice ((0,0))

word: alive ((1,10))

word: almost ((1,9))

word: ask ((5,2))

word: beautiful ((2,7))

word: bird ((2,3),(2,9))

word: blow ((1,3))

word: daddy ((0,8),(3,3),(5,5))

word: emma ((0,1))

word: fiery ((2,2),(2,8))

word: flight ((2,5))

word: flowing ((0,4))

word: hair ((0,6),(1,6))

word: has ((0,2))

word: like ((2,0))

word: long ((0,3))

word: look ((1,8))

word: magical ((3,0))

word: mean ((5,4))

word: more ((4,12))

word: red ((0,5))

word: same ((4,5))

word: say ((0,9))

word: she ((4,0),(5,1))

word: shush ((3,4))

word: shyly ((5,0))

word: such ((3,8))

word: tell ((2,11),(4,1),(4,10))

word: there ((3,5),(5,7))

word: thing ((3,9))

word: through ((1,4))

word: time ((4,6))

word: untamed ((3,2))

word: wanting ((4,7))

word: wind ((1,2))

 

*/

 

SDN — EVPN Overlay 控制面 完成控制面的配置后,当 VxLAN L2 Gateway(e.g. Leaf1)再收到从 Host1 向 Host2 发出的 ARP Request 时,就会先查看自己的 ARP 广播抑制表,发现有 Host2 的 MAC-IP 记录,则直接将 ARP Request 报文中的广播 MAC 地址替换为目的单播 MAC 地址(广播变单播),然后原路 Reply,从而达到 ARP 广播抑制的目的。手动配置的方式虽然简单,但网络中会存在大量的 BUM 洪泛流量,网络扩展性也受到了限制,并不适用于大规模组网场景。 阅读详情

相关推荐

攻克+86手机号Discord验证墙:从“无效”到“成功”的实战指南

本文提供了一份针对+86手机号在Discord注册时频繁遭遇“手机号无效”问题的实战解决指南。文章系统分析了问题根源,并分步详解了从打造纯净网络环境、尝试多种手机号格式(如+86前加0),到更换iOS等客户端设备的有效方法,旨在帮助用户成功完成Discord手机号验证。

mac99的博客 1138

文本文件单词分割程序

如下面一段文本:   Alice Emma has long flowing red hair. Her Daddy says when the wind blows through her hair, it looks almost alive, like a fiery bird in flight. A beautiful fiery bird, he tells her, magica

一页书DevilBox的优快云 1462

魔百和CM211-1刷Armbian全流程:从安卓盒子到Linux服务器的完美变身

本文详细介绍了如何将魔百和CM211-1机顶盒刷入Armbian系统,实现从安卓盒子到Linux服务器的完美变身。涵盖硬件兼容性验证、固件选择、刷机流程、系统优化及常见问题解决,特别适合技术爱好者低成本搭建家庭NAS或开发环境。

weixin_30329623的博客 243

【足迹C++primer】56、文本查询程序

/** * 功能:文本查询程序 * 时间:2014年7月23日10:26:09 * 作者:cutter_point */ #include #include #include #include #include #include #include using namespace std; /* Alice Emma has long flowing red hair. Her Daddy s

cutter_point的专栏 1470

UNet 改进(22):结合Transformer结构

保留了UNet的经典编码器-解码器结构在瓶颈层使用Transformer替代传统的卷积层采用跳跃连接保持空间细节信息使用双卷积块(DoubleConv)作为基础构建模块。

2401_82355416的博客 775

【Metashape精品教程4】软件设置

介绍Metashape软件设置

penglu366366的博客 2953

C++容器和迭代器(二)

vector类的RAII template<typename T, typename A> void vector<T,A>::reserve(int newalloc) { if (newalloc<=space) return; //从不减少分配的内存 T* p = alloc.allocate(newalloc); //分配新空间 f...

宁静以致墨的专栏 230

使用Qt和MX Component插件实现与菱PLC的通信

在本文中,我们介绍了如何使用Qt和MX Component插件实现与菱PLC的通信。我们首先安装和配置了MX Component插件,并在Qt项目中初始化和使用MX Component来连接、读取和写入PLC的数据。安装完成后,您需要在Qt项目中配置MX Component的路径,以便Qt可以找到所需的库文件。在本文中,我们将探讨如何使用Qt和MX Component插件来实现与菱PLC的通信。在主函数中,我们将初始化MX Component,并创建一个与PLC通信的示例。在上面的代码中,我们使用了。

TlScratch的博客 996

《C++ Primer》学习笔记散记……(未完待完篇......)

  前面的话:C++Primer并不适合“初学者”,初学者还是看《C++Primer Plus》我没有看过,但道听途说适合初学者,学习C++的艰辛真是一言难尽!    其实《C++Primer》这本书我一直在看,来来回回,反反复复,因为心浮气躁所以收效不大,其实如果你自认为是理所当然的事情其实你可能并不知道地很清楚,所以我决心从头再看一遍,我要把里面的程序和习题从头到尾彻彻底底地执行和剖析一遍

弥勒日巴的专栏 2410

Ambari 安装部署教程(手把手教学)【超级详细】

本文为读者提供了一套超详细的 Apache Ambari 安装部署教程,采用手把手教学方式,适合初学者及大数据运维人员。内容涵盖前期准备、环境配置、Ambari Server 与 Agent 安装、集群初始化配置、常见问题排查等全流程操作,确保用户能够顺利搭建稳定的 Hadoop 大数据平台管理系统。

Five的博客 1万+

71、CAN总线双绞线绞距与抗共模干扰的定量关系

摘要:本文探讨了CAN总线双绞线绞距与抗共模干扰的定量关系。通过理论推导得出共模电压与绞距平方成正比,绞距越小抑制效果越好。工程实践表明,工业现场推荐绞距不超过30mm,高频干扰场景需优先优化绞距。实测数据验证了绞距均匀性的重要性,建议控制在15-25mm范围,安装时保持绞合结构完整。案例显示,将绞距从50mm改为15mm后,共模干扰从12V降至1.8V,有效解决了CAN通信问题。绞距选择需兼顾理论计算与现场实测,同时注意与屏蔽层的协同设计。

2401_88858637的博客 190

【C++ Primer】第15章 面向对象程序设计 (3)

面向对象程序设计基于 3 个基本概念:数据抽象、继承和动态绑定。

HPP_优快云的博客 409

解锁RK3588+RTL8211F:千兆以太网PHY调优秘籍

本文探讨了RK3588芯片搭配RTL8211F千兆以太网PHY的优化方案。文章首先分析了RK3588和RTL8211F的硬件特性,指出时序问题可能源于时钟信号不稳定、传输延迟和PHY内部逻辑延迟。针对这些问题,提出了选用高质量时钟源、优化PCB布线等时序优化策略,以及合理配置硬件参数、优化网络协议等延迟优化方法。在配置实践部分,详细介绍了硬件连接规范和软件配置步骤,并建议使用Iperf、Ping等工具进行性能测试。最后总结了常见问题解决方案,展望了未来PHY芯片和传输技术的发展趋势。这些优化措施可显著提升网

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 289

类设计者的工具(五):面向对象程序设计示例

本文为《C++ Primer》的读书笔记 目录文本查询程序再探面向对象的解决方案抽象基类将层次关系隐藏于接口类中`Query_base`类和`Query`类 文本查询程序再探 接下来, 我们扩展之前的文本查询程序,用它作为说明继承的最后一个例子。在上一版的程序中, 我们可以查询在文件中某个指定单词的出现情况。我们将在本节扩展该程序使其支持更多更复杂的查询操作。在后面的例子中, 我们将针对下面这个小故事展开查询: Alice Emma has long flowing red hair. Her Daddy

连理o的博客 837

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

C++ 10.3 关联容器map定义以及value_type、key_type、mapped_type

简介 map是<键—值>对的集合 如:map< string ,int> word_count。map类型通常可理解为关联数组:可使用键作为下标来获取一个值,正如内置数组类型一样。而关联的本质在于元素的值与某个特定的键相关联,而并非通过元素在数组中的位置来获取。 要使用map对象,则必须包含map 头文件。 #include < map >. 在定义map 对象时,必须分别指明键和值的类型: 记住!

海螺上的斑点 1万+

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

iostream 库

iostream 库C++的输入/输出设施是由iostream库(iostream library)提供的,它是一个利用多继承和虚拟继承实现的面向对象类层次结构,是作为C++标准库的一个组件而提供的。它为内置数据类型的输入输出提供了支持,也支持文件的输入输出。除此之外,类的设计者可以扩展iostream库,以读写新的类类型。为了在我们的程序中使用iostream库,我们必须包含相关的头文件

sdnxiaotao的专栏 2285

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

emma 小记

--简介 EMMA 是一个用于检测测试代码覆盖率和报告 JAVA 代码覆盖率的开源工具。它不但能很好的用于小型项目,很方便得得出覆盖率报告,而且适用于大型企业级别的项目。 EMMA 有许多优点,首先你能免费得到它,并把它用于自己项目的开发。它支持许多种级别的覆盖率指标:包,类,方法,语句块(basic block)和行,特别是它能测出某一行是否只是被部分覆盖,如条件语句短路的情况。它能

罗马非一日建成 844

CUPTI - The CUDA Profiling Tools Interface

CUPTI - The CUDA Profiling Tools Interface Usage The CUDA Profiling Tools Interface (CUPTI) enables the creation of profiling and tracing tools that target CUDA applications. CUPTI provides four A...

WhateverYoung的专栏 5209

c++ primer(第五版)学习笔记及习题答案代码版(第十四章)重载运算与类型转换

笔记较为零散,都是自己不熟悉的知识点。 习题答案至于一个.h 和.cc 中,需要演示某一题直接修改 #define NUM****, 如运行14.30题为#define NUM1430;Alice Emma has long flowing red hair. Her Daddy says when the wind blows through her hair, it looks almo

refuil的博客 2086

C++ istream_iterator以及cin输入的一些问题

#include #include #include #include #include #include using namespace std; int main() { istream_iterator is(cin); istream_iterator eof; vector text; copy(is, eof, b

Richard Wang的专栏 1400

《C++ Primer》第19章 19.5节习题答案

《C++ Primer》第19章 特殊工具与技术 19.5节 嵌套类 习题答案 练习19.20:将你的QueryResult类嵌套在TextQuery中,然后重新运行12.3.2节(第435页)中使用了TextQuery的程序。 【出题思路】嵌套类的定义与使用练习。 【解答】 class TextQuery { public: class QueryResult; //其他成员的定义 }; class TextQuery::QueryResult { friend s

chenyijun的专栏 722

深挖C++:类和对象(中)

(先进后出)

xys_678的博客 261

跟我学c++中级篇—类型定义的方式

本文系统阐述了编程中类型定义的重要性及c++中的实现方式。重点对比了宏定义、typedef与modern using三种机制,指出using在可读性、灵活性和模板支持上的优势,推荐优先使用。同时提醒开发者注意别名滥用、类型歧义、错误信息冗长等问题,强调统一规范与合理设计。最终结论:在现代c++开发中,应以using为主,兼顾简洁性与可维护性,避免陷入命名混乱与编译困境。

fpcc的专栏 400

【C/C++ 第一次跨越(下):移动语义与 noexcept——不改变行为的性能修复】

本文详解C++11移动语义在迁移至现代C++时的性能优化策略,强调“不改变行为”的前提下通过合理使用移动语义消除深拷贝开销。重点解析移动操作生成规则:析构函数、拷贝函数或const/引用成员会抑制移动构造;noexcept影响std::vector是否选择移动而非回退拷贝。提出“Rule of Zero”原则——用RAII封装资源,避免手动实现特殊成员函数,确保移动语义被正确调用,实现零开销移动与内存安全。

一起学习进步! 298
上一篇: 《C++ Primer》学习笔记散记……(未完待完篇......)
下一篇: C++ Primer 学习笔记-练习6.7的答案错了?
stdHans
博客等级 码龄23年 1粉丝 10原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值