class="tags" href="/C.html" title=
c >
c ontent_views"
c lass="tags" href="/C.html" title=
c >
c lass="markdown_views prism-tomorrow-night">
class="tags" href="/C.html" title=c >c ap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-bloc lass="tags" href="/C.html" title=c >c k" style="-webkit-tap-highlight-c lass="tags" href="/C.html" title=c >c olor: rgba(0, 0, 0, 0);">
class="tags" href="/C.html" title=c >c ="https://i-blog.c lass="tags" href="/C.html" title=c >c sdnimg.c lass="tags" href="/C.html" title=c >c n/direc lass="tags" href="/C.html" title=c >c t/c lass="tags" href="/C.html" title=c >c b7f73c lass="tags" href="/C.html" title=c >c da1a14130840e356c lass="tags" href="/C.html" title=c >c b0b6f9e4.png#pic lass="tags" href="/C.html" title=c >c _c lass="tags" href="/C.html" title=c >c enter" alt="在这里插入图片描述" width="100" />
<
c lass="tags" href="/C.html" title=
c >
c enter>
博客主页: [小ᶻ☡꙳ᵃⁱᵍᶜ꙳]
c lass="tags" href="/C.html" title=
c >
c enter>
<
c lass="tags" href="/C.html" title=
c >
c enter>
本文专栏: C++
c lass="tags" href="/C.html" title=
c >
c enter>
class="tags" href="/C.html" title=c >c ="https://img-blog.c lass="tags" href="/C.html" title=c >c sdnimg.c lass="tags" href="/C.html" title=c >c n/direc lass="tags" href="/C.html" title=c >c t/00d4fdeb7b0d4dbb99e88f325ef249d8.gif#pic lass="tags" href="/C.html" title=c >c _c lass="tags" href="/C.html" title=c >c enter" alt="在这里插入图片描述" width="1000" height="100" />
💯前言
C++计算机软件开发中c lass="tags" href="/C.html" title=c >c ;对字符串进行操作是常见的需求。字符串里的查询功能是基础c lass="tags" href="/C.html" title=c >c ;也是高性能编程中的重要一环。C++ 中提供了完善的字符串操作函数c lass="tags" href="/C.html" title=c >c ;而其中的 <c lass="tags" href="/C.html" title=c >c ode>find()c lass="tags" href="/C.html" title=c >c ode> 函数c lass="tags" href="/C.html" title=c >c ;是用于在字符串中查找子串或字符的工具。 本文将全面解析 C++ 中的 <c lass="tags" href="/C.html" title=c >c ode>find()c lass="tags" href="/C.html" title=c >c ode> 函数c lass="tags" href="/C.html" title=c >c ;包括基础解释c lass="tags" href="/C.html" title=c >c ;示例解析c lass="tags" href="/C.html" title=c >c ;以及实际应用中的特别经验。我们将重点解析不同功能开发情景中的实现c lass="tags" href="/C.html" title=c >c ;并提供简单明显的实验代码。 C++ 参考手册 class="tags" href="/C.html" title=c >c ="https://i-blog.c lass="tags" href="/C.html" title=c >c sdnimg.c lass="tags" href="/C.html" title=c >c n/direc lass="tags" href="/C.html" title=c >c t/f0db7c lass="tags" href="/C.html" title=c >c 348331440fa266b3c lass="tags" href="/C.html" title=c >c 24f558694.png#pic lass="tags" href="/C.html" title=c >c _c lass="tags" href="/C.html" title=c >c enter" alt="在这里插入图片描述" />
💯一、<c lass="tags" href="/C.html" title=c >c ode>find()c lass="tags" href="/C.html" title=c >c ode> 函数概述
1.基本作用
C++ 中的 <c lass="tags" href="/C.html" title=c >c ode>find()c lass="tags" href="/C.html" title=c >c ode> 函数是用于在字符串中查找指定的子串或单个字符c lass="tags" href="/C.html" title=c >c ;并返回子串/字符在字符串中的第一次出现位置。
如果查找成功c lass="tags" href="/C.html" title=c >c ;则返回子串位置的值(起始位置); 如果查找失败c lass="tags" href="/C.html" title=c >c ;则返回特殊值 <c lass="tags" href="/C.html" title=c >c ode>string::nposc lass="tags" href="/C.html" title=c >c ode>c lass="tags" href="/C.html" title=c >c ;表示没有找到。
2.函数形式解释
<c lass="tags" href="/C.html" title=c >c ode>find()c lass="tags" href="/C.html" title=c >c ode> 是字符串类的成员函数c lass="tags" href="/C.html" title=c >c ;提供了多种不同调用模式:
<c lass="tags" href="/C.html" title=c >c ode c lass="tags" href="/C.html" title=c >c lass="prism language-c lass="tags" href="/C.html" title=c >c pp">size_t class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">find class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token keyword">c lass="tags" href="/C.html" title=c >c onst stringclass="tags" href="/C.html" title=c >c lass="token operator">& strclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">, size_t pos class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token number">0 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token keyword">c lass="tags" href="/C.html" title=c >c onst class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// 查找字符串
size_t class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">find class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token keyword">c lass="tags" href="/C.html" title=c >c onst class="tags" href="/C.html" title=c >c lass="token keyword">c lass="tags" href="/C.html" title=c >c har class="tags" href="/C.html" title=c >c lass="token operator">* sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">, size_t pos class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token number">0 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token keyword">c lass="tags" href="/C.html" title=c >c onst class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// 查找 C 风格字符串
size_t class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">find class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token keyword">c lass="tags" href="/C.html" title=c >c onst class="tags" href="/C.html" title=c >c lass="token keyword">c lass="tags" href="/C.html" title=c >c har class="tags" href="/C.html" title=c >c lass="token operator">* sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">, size_t posclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">, size_t nclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token keyword">c lass="tags" href="/C.html" title=c >c onst class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// 查找指定长度子串
size_t class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">find class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token keyword">c lass="tags" href="/C.html" title=c >c har c lass="tags" href="/C.html" title=c >c class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">, size_t pos class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token number">0 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token keyword">c lass="tags" href="/C.html" title=c >c onst class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// 查找单个字符
c lass="tags" href="/C.html" title=c >c ode>
<c lass="tags" href="/C.html" title=c >c ode>strc lass="tags" href="/C.html" title=c >c ode> :指定的查找子串; <c lass="tags" href="/C.html" title=c >c ode>sc lass="tags" href="/C.html" title=c >c ode> : C 风格字符串c lass="tags" href="/C.html" title=c >c ;通过指针传递; <c lass="tags" href="/C.html" title=c >c ode>posc lass="tags" href="/C.html" title=c >c ode> :开始查找的位置c lass="tags" href="/C.html" title=c >c ;默认为 0; <c lass="tags" href="/C.html" title=c >c ode>nc lass="tags" href="/C.html" title=c >c ode> :要匹配的子串长度; <c lass="tags" href="/C.html" title=c >c ode>c lass="tags" href="/C.html" title=c >c c lass="tags" href="/C.html" title=c >c ode> :单个字符。
3.举例:查找失败
如果在字符串中没有找到子串c lass="tags" href="/C.html" title=c >c ;<c lass="tags" href="/C.html" title=c >c ode>find()c lass="tags" href="/C.html" title=c >c ode> 函数将返回字符串类的静态常量 <c lass="tags" href="/C.html" title=c >c ode>nposc lass="tags" href="/C.html" title=c >c ode> c lass="tags" href="/C.html" title=c >c ;表示失败。
<c lass="tags" href="/C.html" title=c >c ode>nposc lass="tags" href="/C.html" title=c >c ode> 是字符串类中定义的静态常量c lass="tags" href="/C.html" title=c >c ;应用于不实效的查找情况:
<c lass="tags" href="/C.html" title=c >c ode c lass="tags" href="/C.html" title=c >c lass="prism language-c lass="tags" href="/C.html" title=c >c pp">class="tags" href="/C.html" title=c >c lass="token keyword">static lass="tags" href="/C.html" title=c >c class="tags" href="/C.html" title=c >c lass="token keyword">c lass="tags" href="/C.html" title=c >c onst size_t npos class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token operator">- class="tags" href="/C.html" title=c >c lass="token number">1 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// npos通常是一个特殊大的值c lass="tags" href="/C.html" title=c >c ;如:18446744073709551615
c lass="tags" href="/C.html" title=c >c ode>
实例:
<c lass="tags" href="/C.html" title=c >c ode c lass="tags" href="/C.html" title=c >c lass="prism language-c lass="tags" href="/C.html" title=c >c pp">class="tags" href="/C.html" title=c >c lass="token mac lass="tags" href="/C.html" title=c >c ro property">class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive-hash"># class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive keyword">inc lass="tags" href="/C.html" title=c >c lude class="tags" href="/C.html" title=c >c lass="token string"><iostream>
class="tags" href="/C.html" title=c >c lass="token mac lass="tags" href="/C.html" title=c >c ro property">class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive-hash"># class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive keyword">inc lass="tags" href="/C.html" title=c >c lude class="tags" href="/C.html" title=c >c lass="token string"><string>
class="tags" href="/C.html" title=c >c lass="token keyword">using class="tags" href="/C.html" title=c >c lass="token keyword">namespac lass="tags" href="/C.html" title=c >c e stdclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token keyword">int class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">main class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">{ string s class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token string">"hello world" class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; size_t n class="tags" href="/C.html" title=c >c lass="token operator">= sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">find class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token string">"bit" class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// "bit" 不存在c lass="tags" href="/C.html" title=c >c ;回调 npos class="tags" href="/C.html" title=c >c lass="token keyword">if class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( n class="tags" href="/C.html" title=c >c lass="token operator">== stringclass="tags" href="/C.html" title=c >c lass="token double-c lass="tags" href="/C.html" title=c >c olon punc lass="tags" href="/C.html" title=c >c tuation">:: nposclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">{ c lass="tags" href="/C.html" title=c >c out class="tags" href="/C.html" title=c >c lass="token operator"><< class="tags" href="/C.html" title=c >c lass="token string">"查找失败" class="tags" href="/C.html" title=c >c lass="token operator"><< endlclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">} class="tags" href="/C.html" title=c >c lass="token keyword">else class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">{ c lass="tags" href="/C.html" title=c >c out class="tags" href="/C.html" title=c >c lass="token operator"><< class="tags" href="/C.html" title=c >c lass="token string">"找到c lass="tags" href="/C.html" title=c >c ;位置是:" class="tags" href="/C.html" title=c >c lass="token operator"><< n class="tags" href="/C.html" title=c >c lass="token operator"><< endlclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">} class="tags" href="/C.html" title=c >c lass="token keyword">return class="tags" href="/C.html" title=c >c lass="token number">0 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">;
class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">}
c lass="tags" href="/C.html" title=c >c ode>
输出: <c lass="tags" href="/C.html" title=c >c ode>查找失败c lass="tags" href="/C.html" title=c >c ode>
💯二、解析和示例解释
1. 基本示例:字符串查找
本例用于查找字符串中指定子串的位置:
<c lass="tags" href="/C.html" title=c >c ode c lass="tags" href="/C.html" title=c >c lass="prism language-c lass="tags" href="/C.html" title=c >c pp">class="tags" href="/C.html" title=c >c lass="token mac lass="tags" href="/C.html" title=c >c ro property">class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive-hash"># class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive keyword">inc lass="tags" href="/C.html" title=c >c lude class="tags" href="/C.html" title=c >c lass="token string"><iostream>
class="tags" href="/C.html" title=c >c lass="token mac lass="tags" href="/C.html" title=c >c ro property">class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive-hash"># class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive keyword">inc lass="tags" href="/C.html" title=c >c lude class="tags" href="/C.html" title=c >c lass="token string"><string>
class="tags" href="/C.html" title=c >c lass="token keyword">using class="tags" href="/C.html" title=c >c lass="token keyword">namespac lass="tags" href="/C.html" title=c >c e stdclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token keyword">int class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">main class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">{ string s class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token string">"hello world hello everyone" class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; string str class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token string">"llo" class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; size_t n class="tags" href="/C.html" title=c >c lass="token operator">= sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">find class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( strclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// 查找字符串 "llo"c lass="tags" href="/C.html" title=c >c ;从字符串开始 c lass="tags" href="/C.html" title=c >c out class="tags" href="/C.html" title=c >c lass="token operator"><< n class="tags" href="/C.html" title=c >c lass="token operator"><< endlclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// 输出:2 n class="tags" href="/C.html" title=c >c lass="token operator">= sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">find class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( strclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">, n class="tags" href="/C.html" title=c >c lass="token operator">+ class="tags" href="/C.html" title=c >c lass="token number">1 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// 从上次位置之后再查找 c lass="tags" href="/C.html" title=c >c out class="tags" href="/C.html" title=c >c lass="token operator"><< n class="tags" href="/C.html" title=c >c lass="token operator"><< endlclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// 输出:14 class="tags" href="/C.html" title=c >c lass="token keyword">return class="tags" href="/C.html" title=c >c lass="token number">0 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">;
class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">}
c lass="tags" href="/C.html" title=c >c ode>
解释:
<c lass="tags" href="/C.html" title=c >c ode>find()c lass="tags" href="/C.html" title=c >c ode> 实现了查找子串的功能c lass="tags" href="/C.html" title=c >c ;并且返回第一次匹配的位置。 完成一次查找后c lass="tags" href="/C.html" title=c >c ;通过 <c lass="tags" href="/C.html" title=c >c ode>n + 1c lass="tags" href="/C.html" title=c >c ode> 跳过已查找部分c lass="tags" href="/C.html" title=c >c ;继续找到下一个第一匹配。
2. 字符查找
如果查找单个字符c lass="tags" href="/C.html" title=c >c ;可使用下列代码:
<c lass="tags" href="/C.html" title=c >c ode c lass="tags" href="/C.html" title=c >c lass="prism language-c lass="tags" href="/C.html" title=c >c pp">class="tags" href="/C.html" title=c >c lass="token mac lass="tags" href="/C.html" title=c >c ro property">class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive-hash"># class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive keyword">inc lass="tags" href="/C.html" title=c >c lude class="tags" href="/C.html" title=c >c lass="token string"><iostream>
class="tags" href="/C.html" title=c >c lass="token mac lass="tags" href="/C.html" title=c >c ro property">class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive-hash"># class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive keyword">inc lass="tags" href="/C.html" title=c >c lude class="tags" href="/C.html" title=c >c lass="token string"><string>
class="tags" href="/C.html" title=c >c lass="token keyword">using class="tags" href="/C.html" title=c >c lass="token keyword">namespac lass="tags" href="/C.html" title=c >c e stdclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token keyword">int class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">main class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">{ string s class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token string">"hello world hello everyone" class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; size_t n class="tags" href="/C.html" title=c >c lass="token operator">= sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">find class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c har">'o' class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// 查找字符 'o'c lass="tags" href="/C.html" title=c >c ;从字符串开始 c lass="tags" href="/C.html" title=c >c out class="tags" href="/C.html" title=c >c lass="token operator"><< n class="tags" href="/C.html" title=c >c lass="token operator"><< endlclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// 输出:4 n class="tags" href="/C.html" title=c >c lass="token operator">= sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">find class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c har">'o' class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">, n class="tags" href="/C.html" title=c >c lass="token operator">+ class="tags" href="/C.html" title=c >c lass="token number">1 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// 从上次位置之后再查找 c lass="tags" href="/C.html" title=c >c out class="tags" href="/C.html" title=c >c lass="token operator"><< n class="tags" href="/C.html" title=c >c lass="token operator"><< endlclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// 输出:7 class="tags" href="/C.html" title=c >c lass="token keyword">return class="tags" href="/C.html" title=c >c lass="token number">0 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">;
class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">}
c lass="tags" href="/C.html" title=c >c ode>
解释:
与字符串查找相比c lass="tags" href="/C.html" title=c >c ;单字符查找更简单c lass="tags" href="/C.html" title=c >c ;参数是一个字符。 <c lass="tags" href="/C.html" title=c >c ode>find()c lass="tags" href="/C.html" title=c >c ode> 会返回字符在字符串中第一次出现的位置c lass="tags" href="/C.html" title=c >c ;如果找到了多次c lass="tags" href="/C.html" title=c >c ;可以通过连续查找进一步获取后续结果。
3. 查找失败处理
通过判断返回值是否为 <c lass="tags" href="/C.html" title=c >c ode>nposc lass="tags" href="/C.html" title=c >c ode>c lass="tags" href="/C.html" title=c >c ;可以确实子串是否存在:
<c lass="tags" href="/C.html" title=c >c ode c lass="tags" href="/C.html" title=c >c lass="prism language-c lass="tags" href="/C.html" title=c >c pp">class="tags" href="/C.html" title=c >c lass="token mac lass="tags" href="/C.html" title=c >c ro property">class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive-hash"># class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive keyword">inc lass="tags" href="/C.html" title=c >c lude class="tags" href="/C.html" title=c >c lass="token string"><iostream>
class="tags" href="/C.html" title=c >c lass="token mac lass="tags" href="/C.html" title=c >c ro property">class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive-hash"># class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive keyword">inc lass="tags" href="/C.html" title=c >c lude class="tags" href="/C.html" title=c >c lass="token string"><string>
class="tags" href="/C.html" title=c >c lass="token keyword">using class="tags" href="/C.html" title=c >c lass="token keyword">namespac lass="tags" href="/C.html" title=c >c e stdclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token keyword">int class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">main class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">{ string s class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token string">"hello world hello everyone" class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; string str class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token string">"bit" class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; size_t n class="tags" href="/C.html" title=c >c lass="token operator">= sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">find class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( strclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token keyword">if class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( n class="tags" href="/C.html" title=c >c lass="token operator">!= stringclass="tags" href="/C.html" title=c >c lass="token double-c lass="tags" href="/C.html" title=c >c olon punc lass="tags" href="/C.html" title=c >c tuation">:: nposclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">{ c lass="tags" href="/C.html" title=c >c out class="tags" href="/C.html" title=c >c lass="token operator"><< class="tags" href="/C.html" title=c >c lass="token string">"找到c lass="tags" href="/C.html" title=c >c ;位置是:" class="tags" href="/C.html" title=c >c lass="token operator"><< n class="tags" href="/C.html" title=c >c lass="token operator"><< endlclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">} class="tags" href="/C.html" title=c >c lass="token keyword">else class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">{ c lass="tags" href="/C.html" title=c >c out class="tags" href="/C.html" title=c >c lass="token operator"><< class="tags" href="/C.html" title=c >c lass="token string">"没有找到" class="tags" href="/C.html" title=c >c lass="token operator"><< endlclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">} class="tags" href="/C.html" title=c >c lass="token keyword">return class="tags" href="/C.html" title=c >c lass="token number">0 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">;
class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">}
c lass="tags" href="/C.html" title=c >c ode>
解释:
<c lass="tags" href="/C.html" title=c >c ode>nposc lass="tags" href="/C.html" title=c >c ode> 是一个特殊值c lass="tags" href="/C.html" title=c >c ;代表未找到子串。 可以通过判断 <c lass="tags" href="/C.html" title=c >c ode>n == string::nposc lass="tags" href="/C.html" title=c >c ode> 确定查找是否成功c lass="tags" href="/C.html" title=c >c ;并做对应处理。
💯三、应用提示
1. 迭代查找子串
一些应用场景需要迭代找出所有匹配位置:
<c lass="tags" href="/C.html" title=c >c ode c lass="tags" href="/C.html" title=c >c lass="prism language-c lass="tags" href="/C.html" title=c >c pp">class="tags" href="/C.html" title=c >c lass="token mac lass="tags" href="/C.html" title=c >c ro property">class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive-hash"># class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive keyword">inc lass="tags" href="/C.html" title=c >c lude class="tags" href="/C.html" title=c >c lass="token string"><iostream>
class="tags" href="/C.html" title=c >c lass="token mac lass="tags" href="/C.html" title=c >c ro property">class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive-hash"># class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive keyword">inc lass="tags" href="/C.html" title=c >c lude class="tags" href="/C.html" title=c >c lass="token string"><string>
class="tags" href="/C.html" title=c >c lass="token keyword">using class="tags" href="/C.html" title=c >c lass="token keyword">namespac lass="tags" href="/C.html" title=c >c e stdclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token keyword">int class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">main class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">{ string s class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token string">"hello world hello everyone" class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; string str class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token string">"llo" class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; size_t pos class="tags" href="/C.html" title=c >c lass="token operator">= sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">find class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( strclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token keyword">while class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( pos class="tags" href="/C.html" title=c >c lass="token operator">!= stringclass="tags" href="/C.html" title=c >c lass="token double-c lass="tags" href="/C.html" title=c >c olon punc lass="tags" href="/C.html" title=c >c tuation">:: nposclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">{ c lass="tags" href="/C.html" title=c >c out class="tags" href="/C.html" title=c >c lass="token operator"><< class="tags" href="/C.html" title=c >c lass="token string">"找到:" class="tags" href="/C.html" title=c >c lass="token operator"><< pos class="tags" href="/C.html" title=c >c lass="token operator"><< endlclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; pos class="tags" href="/C.html" title=c >c lass="token operator">= sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">find class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( strclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">, pos class="tags" href="/C.html" title=c >c lass="token operator">+ class="tags" href="/C.html" title=c >c lass="token number">1 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// 继续查找 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">} class="tags" href="/C.html" title=c >c lass="token keyword">return class="tags" href="/C.html" title=c >c lass="token number">0 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">;
class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">}
c lass="tags" href="/C.html" title=c >c ode>
输出:
<c lass="tags" href="/C.html" title=c >c ode>找到:2
找到:14
c lass="tags" href="/C.html" title=c >c ode>
2. 提取上下文信息
<c lass="tags" href="/C.html" title=c >c ode>find()c lass="tags" href="/C.html" title=c >c ode> 函数还可以结合 <c lass="tags" href="/C.html" title=c >c ode>substr()c lass="tags" href="/C.html" title=c >c ode> 提取匹配子串周围的上下文:
<c lass="tags" href="/C.html" title=c >c ode c lass="tags" href="/C.html" title=c >c lass="prism language-c lass="tags" href="/C.html" title=c >c pp">class="tags" href="/C.html" title=c >c lass="token mac lass="tags" href="/C.html" title=c >c ro property">class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive-hash"># class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive keyword">inc lass="tags" href="/C.html" title=c >c lude class="tags" href="/C.html" title=c >c lass="token string"><iostream>
class="tags" href="/C.html" title=c >c lass="token mac lass="tags" href="/C.html" title=c >c ro property">class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive-hash"># class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive keyword">inc lass="tags" href="/C.html" title=c >c lude class="tags" href="/C.html" title=c >c lass="token string"><string>
class="tags" href="/C.html" title=c >c lass="token keyword">using class="tags" href="/C.html" title=c >c lass="token keyword">namespac lass="tags" href="/C.html" title=c >c e stdclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token keyword">int class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">main class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">{ string s class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token string">"hello world hello everyone" class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; string str class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token string">"world" class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; size_t pos class="tags" href="/C.html" title=c >c lass="token operator">= sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">find class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( strclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token keyword">if class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( pos class="tags" href="/C.html" title=c >c lass="token operator">!= stringclass="tags" href="/C.html" title=c >c lass="token double-c lass="tags" href="/C.html" title=c >c olon punc lass="tags" href="/C.html" title=c >c tuation">:: nposclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">{ size_t start class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( pos class="tags" href="/C.html" title=c >c lass="token operator">> class="tags" href="/C.html" title=c >c lass="token number">5 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token operator">? pos class="tags" href="/C.html" title=c >c lass="token operator">- class="tags" href="/C.html" title=c >c lass="token number">5 class="tags" href="/C.html" title=c >c lass="token operator">: class="tags" href="/C.html" title=c >c lass="token number">0 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; size_t len class="tags" href="/C.html" title=c >c lass="token operator">= strclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">length class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token operator">+ class="tags" href="/C.html" title=c >c lass="token number">10 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; c lass="tags" href="/C.html" title=c >c out class="tags" href="/C.html" title=c >c lass="token operator"><< class="tags" href="/C.html" title=c >c lass="token string">"上下文:" class="tags" href="/C.html" title=c >c lass="token operator"><< sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">substr class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( startclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">, lenclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token operator"><< endlclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">} class="tags" href="/C.html" title=c >c lass="token keyword">return class="tags" href="/C.html" title=c >c lass="token number">0 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">;
class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">}
c lass="tags" href="/C.html" title=c >c ode>
输出:
<c lass="tags" href="/C.html" title=c >c ode>上下文:hello world hello
c lass="tags" href="/C.html" title=c >c ode>
3. 忽略大小写查找
<c lass="tags" href="/C.html" title=c >c ode>find()c lass="tags" href="/C.html" title=c >c ode> 函数默认区分大小写。如果需要忽略大小写c lass="tags" href="/C.html" title=c >c ;可以先将字符串转换为小写后再查找:
<c lass="tags" href="/C.html" title=c >c ode c lass="tags" href="/C.html" title=c >c lass="prism language-c lass="tags" href="/C.html" title=c >c pp">class="tags" href="/C.html" title=c >c lass="token mac lass="tags" href="/C.html" title=c >c ro property">class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive-hash"># class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive keyword">inc lass="tags" href="/C.html" title=c >c lude class="tags" href="/C.html" title=c >c lass="token string"><iostream>
class="tags" href="/C.html" title=c >c lass="token mac lass="tags" href="/C.html" title=c >c ro property">class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive-hash"># class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive keyword">inc lass="tags" href="/C.html" title=c >c lude class="tags" href="/C.html" title=c >c lass="token string"><string>
class="tags" href="/C.html" title=c >c lass="token mac lass="tags" href="/C.html" title=c >c ro property">class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive-hash"># class="tags" href="/C.html" title=c >c lass="token direc lass="tags" href="/C.html" title=c >c tive keyword">inc lass="tags" href="/C.html" title=c >c lude class="tags" href="/C.html" title=c >c lass="token string"><algorithm>
class="tags" href="/C.html" title=c >c lass="token keyword">using class="tags" href="/C.html" title=c >c lass="token keyword">namespac lass="tags" href="/C.html" title=c >c e stdclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token keyword">int class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">main class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">{ string s class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token string">"Hello World Hello Everyone" class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; string str class="tags" href="/C.html" title=c >c lass="token operator">= class="tags" href="/C.html" title=c >c lass="token string">"hello" class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token c lass="tags" href="/C.html" title=c >c omment">// 转换为小写 class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">transform class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">begin class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">, sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">end class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">, sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">begin class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">, class="tags" href="/C.html" title=c >c lass="token double-c lass="tags" href="/C.html" title=c >c olon punc lass="tags" href="/C.html" title=c >c tuation">:: tolowerclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">transform class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( strclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">begin class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">, strclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">end class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">, strclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">begin class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">, class="tags" href="/C.html" title=c >c lass="token double-c lass="tags" href="/C.html" title=c >c olon punc lass="tags" href="/C.html" title=c >c tuation">:: tolowerclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; size_t pos class="tags" href="/C.html" title=c >c lass="token operator">= sclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">. class="tags" href="/C.html" title=c >c lass="token func lass="tags" href="/C.html" title=c >c tion">find class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( strclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token keyword">if class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">( pos class="tags" href="/C.html" title=c >c lass="token operator">!= stringclass="tags" href="/C.html" title=c >c lass="token double-c lass="tags" href="/C.html" title=c >c olon punc lass="tags" href="/C.html" title=c >c tuation">:: nposclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">) class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">{ c lass="tags" href="/C.html" title=c >c out class="tags" href="/C.html" title=c >c lass="token operator"><< class="tags" href="/C.html" title=c >c lass="token string">"找到c lass="tags" href="/C.html" title=c >c ;位置是:" class="tags" href="/C.html" title=c >c lass="token operator"><< pos class="tags" href="/C.html" title=c >c lass="token operator"><< endlclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">} class="tags" href="/C.html" title=c >c lass="token keyword">else class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">{ c lass="tags" href="/C.html" title=c >c out class="tags" href="/C.html" title=c >c lass="token operator"><< class="tags" href="/C.html" title=c >c lass="token string">"没有找到" class="tags" href="/C.html" title=c >c lass="token operator"><< endlclass="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">; class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">} class="tags" href="/C.html" title=c >c lass="token keyword">return class="tags" href="/C.html" title=c >c lass="token number">0 class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">;
class="tags" href="/C.html" title=c >c lass="token punc lass="tags" href="/C.html" title=c >c tuation">}
c lass="tags" href="/C.html" title=c >c ode>
输出:
<c lass="tags" href="/C.html" title=c >c ode>找到c lass="tags" href="/C.html" title=c >c ;位置是:0
c lass="tags" href="/C.html" title=c >c ode>
💯四、小结
C++ 中的 <c lass="tags" href="/C.html" title=c >c ode>find()c lass="tags" href="/C.html" title=c >c ode> 函数是字符串操作中极其重要的工具。通过对其多种使用方法的学习c lass="tags" href="/C.html" title=c >c ;我们可以解决多种字符串匹配问题:
基本查找功能c lass="tags" href="/C.html" title=c >c ;用于快速定位子串或字符; 通过 <c lass="tags" href="/C.html" title=c >c ode>nposc lass="tags" href="/C.html" title=c >c ode> 判断查找失败c lass="tags" href="/C.html" title=c >c ;确保程序稳定性; 结合循环c lass="tags" href="/C.html" title=c >c ;实现多次查找或全文匹配; 配合 <c lass="tags" href="/C.html" title=c >c ode>substr()c lass="tags" href="/C.html" title=c >c ode> 等函数c lass="tags" href="/C.html" title=c >c ;提取匹配上下文。
此外c lass="tags" href="/C.html" title=c >c ;在实际开发中c lass="tags" href="/C.html" title=c >c ;还可以通过忽略大小写等变形用法来满足不同场景需求。希望本文能够帮助读者深入理解并熟练掌握 <c lass="tags" href="/C.html" title=c >c ode>find()c lass="tags" href="/C.html" title=c >c ode> 函数的使用。
class="tags" href="/C.html" title=c >c ="https://img-blog.c lass="tags" href="/C.html" title=c >c sdnimg.c lass="tags" href="/C.html" title=c >c n/direc lass="tags" href="/C.html" title=c >c t/00d4fdeb7b0d4dbb99e88f325ef249d8.gif#pic lass="tags" href="/C.html" title=c >c _c lass="tags" href="/C.html" title=c >c enter" alt="在这里插入图片描述" width="1000" height="100" />
class="tags" href="/C.html" title=c >c ="https://i-blog.c lass="tags" href="/C.html" title=c >c sdnimg.c lass="tags" href="/C.html" title=c >c n/direc lass="tags" href="/C.html" title=c >c t/fc lass="tags" href="/C.html" title=c >c 6ac lass="tags" href="/C.html" title=c >c 6d93b4745b591bb8a8e48f86779.png#pic lass="tags" href="/C.html" title=c >c _right" alt="在这里插入图片描述" width="1" /> class="tags" href="/C.html" title=c >c ="https://i-blog.c lass="tags" href="/C.html" title=c >c sdnimg.c lass="tags" href="/C.html" title=c >c n/direc lass="tags" href="/C.html" title=c >c t/fc lass="tags" href="/C.html" title=c >c 6ac lass="tags" href="/C.html" title=c >c 6d93b4745b591bb8a8e48f86779.png#pic lass="tags" href="/C.html" title=c >c _right" alt="在这里插入图片描述" width="1" /> class="tags" href="/C.html" title=c >c ="https://i-blog.c lass="tags" href="/C.html" title=c >c sdnimg.c lass="tags" href="/C.html" title=c >c n/direc lass="tags" href="/C.html" title=c >c t/fc lass="tags" href="/C.html" title=c >c 6ac lass="tags" href="/C.html" title=c >c 6d93b4745b591bb8a8e48f86779.png#pic lass="tags" href="/C.html" title=c >c _right" alt="在这里插入图片描述" width="1" /> class="tags" href="/C.html" title=c >c ="https://i-blog.c lass="tags" href="/C.html" title=c >c sdnimg.c lass="tags" href="/C.html" title=c >c n/direc lass="tags" href="/C.html" title=c >c t/fc lass="tags" href="/C.html" title=c >c 6ac lass="tags" href="/C.html" title=c >c 6d93b4745b591bb8a8e48f86779.png#pic lass="tags" href="/C.html" title=c >c _right" alt="在这里插入图片描述" width="1" /> class="tags" href="/C.html" title=c >c ="https://i-blog.c lass="tags" href="/C.html" title=c >c sdnimg.c lass="tags" href="/C.html" title=c >c n/direc lass="tags" href="/C.html" title=c >c t/fc lass="tags" href="/C.html" title=c >c 6ac lass="tags" href="/C.html" title=c >c 6d93b4745b591bb8a8e48f86779.png#pic lass="tags" href="/C.html" title=c >c _right" alt="在这里插入图片描述" width="1" /> class="tags" href="/C.html" title=c >c ="https://i-blog.c lass="tags" href="/C.html" title=c >c sdnimg.c lass="tags" href="/C.html" title=c >c n/direc lass="tags" href="/C.html" title=c >c t/fc lass="tags" href="/C.html" title=c >c 6ac lass="tags" href="/C.html" title=c >c 6d93b4745b591bb8a8e48f86779.png#pic lass="tags" href="/C.html" title=c >c _right" alt="在这里插入图片描述" width="1" /> class="tags" href="/C.html" title=c >c ="https://i-blog.c lass="tags" href="/C.html" title=c >c sdnimg.c lass="tags" href="/C.html" title=c >c n/direc lass="tags" href="/C.html" title=c >c t/fc lass="tags" href="/C.html" title=c >c 6ac lass="tags" href="/C.html" title=c >c 6d93b4745b591bb8a8e48f86779.png#pic lass="tags" href="/C.html" title=c >c _right" alt="在这里插入图片描述" width="1" /> class="tags" href="/C.html" title=c >c ="https://i-blog.c lass="tags" href="/C.html" title=c >c sdnimg.c lass="tags" href="/C.html" title=c >c n/direc lass="tags" href="/C.html" title=c >c t/fc lass="tags" href="/C.html" title=c >c 6ac lass="tags" href="/C.html" title=c >c 6d93b4745b591bb8a8e48f86779.png#pic lass="tags" href="/C.html" title=c >c _right" alt="在这里插入图片描述" width="1" /> class="tags" href="/C.html" title=c >c ="https://i-blog.c lass="tags" href="/C.html" title=c >c sdnimg.c lass="tags" href="/C.html" title=c >c n/direc lass="tags" href="/C.html" title=c >c t/fc lass="tags" href="/C.html" title=c >c 6ac lass="tags" href="/C.html" title=c >c 6d93b4745b591bb8a8e48f86779.png#pic lass="tags" href="/C.html" title=c >c _right" alt="在这里插入图片描述" width="1" /> class="tags" href="/C.html" title=c >c ="https://i-blog.c lass="tags" href="/C.html" title=c >c sdnimg.c lass="tags" href="/C.html" title=c >c n/direc lass="tags" href="/C.html" title=c >c t/fc lass="tags" href="/C.html" title=c >c 6ac lass="tags" href="/C.html" title=c >c 6d93b4745b591bb8a8e48f86779.png#pic lass="tags" href="/C.html" title=c >c _right" alt="在这里插入图片描述" width="1" />
学习C++的建议
C++ 是一门强大且广泛应用的编程语言c lass="tags" href="/C.html" title=c >c ;无论是系统开发、游戏开发还是高性能计算c lass="tags" href="/C.html" title=c >c ;它都有不可替代的地位。然而c lass="tags" href="/C.html" title=c >c ;学习C++的道路可能是陡峭的c lass="tags" href="/C.html" title=c >c ;为了帮助你更高效地掌握这门语言c lass="tags" href="/C.html" title=c >c ;我总结了一些学习建议和经验。
1. 理解C++的基础 学习重点:
掌握基本语法 : 学会声明变量、条件语句、循环、函数等核心语法。 掌握数组、指针、引用等基础知识。 熟悉标准输入输出 : 掌握 <c lass="tags" href="/C.html" title=c >c ode>c lass="tags" href="/C.html" title=c >c inc lass="tags" href="/C.html" title=c >c ode> 和 <c lass="tags" href="/C.html" title=c >c ode>c lass="tags" href="/C.html" title=c >c outc lass="tags" href="/C.html" title=c >c ode> 的用法。 理解格式化输出c lass="tags" href="/C.html" title=c >c ;例如 <c lass="tags" href="/C.html" title=c >c ode>std::setwc lass="tags" href="/C.html" title=c >c ode> 和 <c lass="tags" href="/C.html" title=c >c ode>std::fixedc lass="tags" href="/C.html" title=c >c ode>。 记住编译器的角色 : 理解源代码如何通过编译器转换为可执行程序c lass="tags" href="/C.html" title=c >c ;选择一款好的IDE(如Visual Studio、Clion、VSCode)。
class="tags" href="/C.html" title=c >c kquote> 建议 :用大量小程序练习这些基础语法c lass="tags" href="/C.html" title=c >c ;比如写一个计算器、模拟猜数字游戏等。
class="tags" href="/C.html" title=
c >
c kquote>
2. 深入学习C++的特性 学习重点:
面向对象编程(OOP) : 理解类和对象c lass="tags" href="/C.html" title=c >c ;熟悉如何定义类、成员变量和成员函数。 掌握封装、继承、多态三大核心特性。 内存管理 : 理解指针的用法c lass="tags" href="/C.html" title=c >c ;掌握动态内存分配(<c lass="tags" href="/C.html" title=c >c ode>newc lass="tags" href="/C.html" title=c >c ode> 和 <c lass="tags" href="/C.html" title=c >c ode>deletec lass="tags" href="/C.html" title=c >c ode>)。 学习如何避免内存泄漏c lass="tags" href="/C.html" title=c >c ;熟悉智能指针(如<c lass="tags" href="/C.html" title=c >c ode>std::unique_ptrc lass="tags" href="/C.html" title=c >c ode> 和 <c lass="tags" href="/C.html" title=c >c ode>std::shared_ptrc lass="tags" href="/C.html" title=c >c ode>)。 标准模板库(STL) : 熟悉常用的容器(如<c lass="tags" href="/C.html" title=c >c ode>vec lass="tags" href="/C.html" title=c >c torc lass="tags" href="/C.html" title=c >c ode>、<c lass="tags" href="/C.html" title=c >c ode>mapc lass="tags" href="/C.html" title=c >c ode>、<c lass="tags" href="/C.html" title=c >c ode>setc lass="tags" href="/C.html" title=c >c ode>)和算法(如<c lass="tags" href="/C.html" title=c >c ode>sortc lass="tags" href="/C.html" title=c >c ode>、<c lass="tags" href="/C.html" title=c >c ode>findc lass="tags" href="/C.html" title=c >c ode>)。 掌握迭代器的用法。 异常处理 : 学习使用<c lass="tags" href="/C.html" title=c >c ode>try-c lass="tags" href="/C.html" title=c >c atc lass="tags" href="/C.html" title=c >c hc lass="tags" href="/C.html" title=c >c ode>块处理异常。 理解异常的用途以及如何设计健壮的代码。
class="tags" href="/C.html" title=c >c kquote> 建议 :尝试开发一个小型项目c lass="tags" href="/C.html" title=c >c ;比如一个学生管理系统c lass="tags" href="/C.html" title=c >c ;综合应用类、STL、指针和动态内存分配。
class="tags" href="/C.html" title=
c >
c kquote>
3. 掌握进阶内容 学习重点:
模板 : 理解函数模板和类模板c lass="tags" href="/C.html" title=c >c ;掌握泛型编程思想。 学习模板特化和模板元编程的基本概念。 多线程与并发 : 学习 C++11 提供的多线程支持(如<c lass="tags" href="/C.html" title=c >c ode>std::threadc lass="tags" href="/C.html" title=c >c ode>)。 熟悉互斥锁(<c lass="tags" href="/C.html" title=c >c ode>std::mutexc lass="tags" href="/C.html" title=c >c ode>)和条件变量(<c lass="tags" href="/C.html" title=c >c ode>std::c lass="tags" href="/C.html" title=c >c ondition_variablec lass="tags" href="/C.html" title=c >c ode>)。 C++与C的兼容性 : 学习如何在C++中使用C语言代码c lass="tags" href="/C.html" title=c >c ;理解C和C++的区别。 掌握C风格字符串(<c lass="tags" href="/C.html" title=c >c ode>c lass="tags" href="/C.html" title=c >c har[]c lass="tags" href="/C.html" title=c >c ode>)和C++字符串(<c lass="tags" href="/C.html" title=c >c ode>std::stringc lass="tags" href="/C.html" title=c >c ode>)的转换。
class="tags" href="/C.html" title=c >c kquote> 建议 :在这一阶段c lass="tags" href="/C.html" title=c >c ;可以挑战更复杂的项目c lass="tags" href="/C.html" title=c >c ;比如开发一个小型的HTTP服务器c lass="tags" href="/C.html" title=c >c ;学习网络编程并结合多线程。
class="tags" href="/C.html" title=
c >
c kquote>
4. 学习资源与实践方法 学习资源:
书籍 : 《C++ Primer》:非常适合初学者的经典书籍。 《Effec lass="tags" href="/C.html" title=c >c tive C++》:进阶学习C++最佳实践的指南。 《The C++ Programming Language》:Bjarne Stroustrup(C++之父)的权威著作。 在线课程 : Coursera 上的 C++ 编程课程。 YouTube 上免费的 C++ 系列教程。 社区与文档 : 参与C++相关的论坛(如CSDN、Stac lass="tags" href="/C.html" title=c >c k Overflow)。 阅读官方文档(https://en.c lass="tags" href="/C.html" title=c >c ppreferenc lass="tags" href="/C.html" title=c >c e.c lass="tags" href="/C.html" title=c >c om)。
实践方法:
多写代码c lass="tags" href="/C.html" title=c >c ;多调试 : 每学一个概念后c lass="tags" href="/C.html" title=c >c ;写至少两个示例代码并进行调试。 做小项目 : 从简单的控制台程序开始c lass="tags" href="/C.html" title=c >c ;比如文件读写、计算器、小游戏等。 慢慢过渡到图形界面或网络程序开发。 阅读他人代码 : 阅读开源项目的代码c lass="tags" href="/C.html" title=c >c ;理解优秀代码的设计思路。 参加编程比赛 : 比如 LeetCode 或 Codeforc lass="tags" href="/C.html" title=c >c esc lass="tags" href="/C.html" title=c >c ;可以帮助你提升算法能力和C++的熟练度。
5. 保持耐心与兴趣 学习C++可能会面临以下困难:
复杂的语法 :如模板、智能指针、多线程等。调试困难 :指针错误、内存泄漏、未定义行为可能让人头疼。
如何应对:
将大问题拆解成小问题c lass="tags" href="/C.html" title=c >c ;逐步解决。 不断重复基础知识c lass="tags" href="/C.html" title=c >c ;以加深理解。 保持兴趣c lass="tags" href="/C.html" title=c >c ;尝试一些有趣的项目c lass="tags" href="/C.html" title=c >c ;比如写一个游戏、制作一个简单的图形程序。
小结 学习C++需要一个循序渐进的过程c lass="tags" href="/C.html" title=c >c ;从基础语法到面向对象编程c lass="tags" href="/C.html" title=c >c ;再到进阶的模板和并发编程c lass="tags" href="/C.html" title=c >c ;每一步都需要耐心和实践。通过充分利用学习资源、进行大量编码练习c lass="tags" href="/C.html" title=c >c ;以及挑战实际项目c lass="tags" href="/C.html" title=c >c ;你一定可以成为C++的高手。记住c lass="tags" href="/C.html" title=c >c ;学习的核心在于理解c lass="tags" href="/C.html" title=c >c ;而非死记硬背。
祝你学有所成c lass="tags" href="/C.html" title=c >c ;享受C++编程的乐趣!