在atl中,使用std:string如何判断一个字符串包含另一个字符串?

gzhoney 2007-09-14 04:06:24
不自己写函数,有没有现成的方法可以调用呢?
...全文
940 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jxufeng 2007-09-18
  • 打赏
  • 举报
回复
string str;
str=L"sdfsadf";
int pos =str.find(L"sa");
pos=-1 没有找到,pos大于0就是找到的位置
dyw 2007-09-15
  • 打赏
  • 举报
回复
This sample code searches for every instance of the string "cat" in a given string and counts the total number of instances:

string input;
int i = 0;
int cat_appearances = 0;

getline(cin, input, '\n');

i = input.find("cat", 0);
for(; i != string::npos; i = input.find("cat", i))
{
cat_appearances++;
i++; // Move past the last discovered instance to avoid finding same
// string
}
cout<<cat_appearances;
huzs_82 2007-09-14
  • 打赏
  • 举报
回复
这是STL里的吧?
string里包含了basic_string类,
调用find方法:
basic_string::find
size_type find(E c, size_type pos = 0) const;
size_type find(const E *s, size_type pos = 0) const;
size_type find(const E *s, size_type pos, size_type n) const;
size_type find(const basic_string& str, size_type pos = 0) const;

If it succeeds, it returns the position where the matching subsequence begins. Otherwise, the function returns npos.
(basic_string::npos
static const size_type npos = -1;)
如果成功找到返回位置,否则返回-1.
Yofoo 2007-09-14
  • 打赏
  • 举报
回复
strstr() == NULL
gzhoney 2007-09-14
  • 打赏
  • 举报
回复
怎样用呢,能不能举个例子,马上散分结贴!
ouyh12345 2007-09-14
  • 打赏
  • 举报
回复
string::find
代号为X3的C++轻量级通用插件框架平台是一套通用的C++轻量级插件体系,由多个独立插件模块组成。应用程序可以基于X3插件框架进行快速开发,X3插件框架的插件既可以单独使用,又可以灵活组合使用。X3插件框架采用VC++开发,没有使用MFC、ATL、COM,已经过3年十几个系统的实际使用验证。 目前X3插件框架包括插件内核部分(插件基础、插件管理器、Observer管理器插件、日志管理器插件)和实用技术插件(XML读写封装插件、数据库操作封装插件、文件操作实用插件、文本操作实用插件、本地化字符串表插件等)。 X3插件框架的特点有: a) 接口定义简单灵活 采用普通的C++接口,即由纯虚函数组成的结构体,不需要特殊的基类,不需要宏和UUID申明;同时可以使用C++的各种变量类型,不受COM接口那样的约束。例如下面的接口Ix_定义: interface Ix_Example { virtual void Foo() = 0; virtual void* GetData(std::vector& items) = 0; }; b) 接口与实现分离 对外提供接口文件,在插件内部用类来实现一个或多个接口,不需要对外导出该类或暴露实现细节。这样还有一个好处是只有约定了接口就可以让多个模块并行开发,模块相互之间不存在编译依赖(不需要其他插件的LIB等文件),这可用于测试驱动开发模式。 c) 多接口转换、引用计数管理 采用智能指针类来管理接口的引用计数及生命期,可从一个接口动态转换为另一个接口(内部采用C++的RTTI机制动态转换),可以区分插件内部的接口引用和插件外部的接口引用。 d) 模块透明部署 一个模块只需要使用其他模块的接口,不需要关心该接口是在哪个插件实现的。可以根据需要将各个实现类进行合并或拆分,使其分布到不同插件,而接口使用者不受影响。另外,插件部署于哪个目录也不影响插件接口的使用。 e) 模块可替换、可扩展 可根据需要替换某个插件,只有该插件实现了相同的接口,即使内部功能不相同,这样就实现了插件可替换、按需组合。通过在新的插件支持更多的接口,可扩展更多的功能。可以在新插件局部替换原有插件的某些接口或部分函数,实现重用和扩展。 f) 线程安全性 本插件机制所提供的内部实现文件考虑了线程安全性,允许多线程访问而不冲突,同时采用的是轻量级的锁定机制(计数原子锁定),运行开销很小。 g) 跨版本 允许不同版本的VC++开发的插件相互调用对方的接口,虽然实际一般不需要这样做。由于没有采用VC++特殊的编译指令,因此容易移植到其他开发平台下。 编译运行环境 本插件机制采用C++实现,用到了C++的RTTI机制和少量Windows API函数,没有使用MFC、ATL、STL,没有使用LIB文件,外部依赖文件少,没有使用VC++特殊编译指令。 编译环境为Visual C++ 6.0/2003/2005/2008/2010,其他C++开发平台下待测试(从实现原理上看应该没问题)。 运行环境为Windows 2000及以后的操作系统,Windows 98需要安装UNICODE支持包。 X3插件框架目前在局部范围内开放源码,还未在公共开源网站范围正式开放。可以学习研究、任意修改改进,但不可以换成其他作者另外发布,转载时请列出来源。 有改进意见可在博客地址或者邮件提出。 博客:http://www.cnblogs.com/rhcad 邮件:rhcad@hotmail.com 详细描述见 http://www.cnblogs.com/rhcad/archive/2010/09/27/1836943.html 附件内容: .\Product_vc100.sln .\Product_vc60.dsw .\Product_vc80.sln .\Product_vc90.sln .\Code ------\pkg_Core ------\pkg_Example ------\pkg_UnitTest ------\pkg_Core\Interface ------\pkg_Core\Modules ------\pkg_Core\Interface\AppUI ------\pkg_Core\Interface\ChangeObserver ------\pkg_Core\Interface\Ix_Object.h ------\pkg_Core\Interface\Ix_ObjectFactory.h ------\pkg_Core\Interface\Log ------\pkg_Core\Interface\Module ------\pkg_Core\Interface\PluginManager ------\pkg_Core\Interface\UtilFunc ------\pkg_Core\Interface\Utility ------\pkg_Core\Interface\XComPtr.h ------\pkg_Core\Interface\Xml ------\pkg_Core\Interface\AppUI\CmdMsgObserverSimple.h ------\pkg_Core\Interface\AppUI\Cx_CreateWnd.h ------\pkg_Core\Interface\AppUI\Ix_CreateWnd.h ------\pkg_Core\Interface\AppUI\RawCmdMsgObserver.h ------\pkg_Core\Interface\ChangeObserver\ChangeNotifyData.h ------\pkg_Core\Interface\ChangeObserver\Ix_ChangeManager.h ------\pkg_Core\Interface\ChangeObserver\Ix_ChangeObserver.h ------\pkg_Core\Interface\Log\DebugR.cpp ------\pkg_Core\Interface\Log\DebugR.h ------\pkg_Core\Interface\Log\ILogObserver.h ------\pkg_Core\Interface\Log\Ix_LogManager.h ------\pkg_Core\Interface\Log\LogHelper.h ------\pkg_Core\Interface\Module\Cx_Module.h ------\pkg_Core\Interface\Module\Cx_Object.h ------\pkg_Core\Interface\Module\Cx_SimpleObject.h ------\pkg_Core\Interface\Module\Cx_SingletonObject.h ------\pkg_Core\Interface\Module\Ix_Module.h ------\pkg_Core\Interface\Module\XClassItem.h ------\pkg_Core\Interface\Module\XModuleImpl.h ------\pkg_Core\Interface\Module\XModuleItem.h ------\pkg_Core\Interface\Module\XModuleMacro.h ------\pkg_Core\Interface\PluginManager\Ix_PluginLoader.h ------\pkg_Core\Interface\PluginManager\PluginManager.h ------\pkg_Core\Interface\PluginManager\XComCreator.h ------\pkg_Core\Interface\UtilFunc\AutoNew.h ------\pkg_Core\Interface\UtilFunc\ConvStr.h ------\pkg_Core\Interface\UtilFunc\ctrim.h ------\pkg_Core\Interface\UtilFunc\func_s.h ------\pkg_Core\Interface\UtilFunc\LockCount.h ------\pkg_Core\Interface\UtilFunc\LockSyn.h ------\pkg_Core\Interface\UtilFunc\ReadInts.h ------\pkg_Core\Interface\UtilFunc\RelToAbs.h ------\pkg_Core\Interface\UtilFunc\RoundStr.h ------\pkg_Core\Interface\UtilFunc\SafeCall.h ------\pkg_Core\Interface\UtilFunc\ScanFiles.h ------\pkg_Core\Interface\UtilFunc\SysErrStr.h ------\pkg_Core\Interface\UtilFunc\vecfunc.h ------\pkg_Core\Interface\UtilFunc\vecptr.h ------\pkg_Core\Interface\Utility\ClsID_TextUtil.h ------\pkg_Core\Interface\Utility\Ix_ClipboardUtil.h ------\pkg_Core\Interface\Utility\Ix_ConfigDBFactory.h ------\pkg_Core\Interface\Utility\Ix_FileTransaction.h ------\pkg_Core\Interface\Utility\Ix_FileUtility.h ------\pkg_Core\Interface\Utility\Ix_FileVersion.h ------\pkg_Core\Interface\Utility\Ix_GuidGenerator.h ------\pkg_Core\Interface\Utility\Ix_StringConvert.h ------\pkg_Core\Interface\Utility\Ix_TempFolder.h ------\pkg_Core\Interface\Utility\Ix_TextFileUtil.h ------\pkg_Core\Interface\Xml\ConfigIOSection.h ------\pkg_Core\Interface\Xml\IFileCryptHandler.h ------\pkg_Core\Interface\Xml\Ix_ConfigData.h ------\pkg_Core\Interface\Xml\Ix_ConfigSection.h ------\pkg_Core\Interface\Xml\Ix_ConfigSectionXml.h ------\pkg_Core\Interface\Xml\Ix_ConfigTransaction.h ------\pkg_Core\Interface\Xml\Ix_ConfigXml.h ------\pkg_Core\Interface\Xml\Ix_StringTable.h ------\pkg_Core\Interface\Xml\Ix_UIConfig.h ------\pkg_Core\Modules\ChangeManager\... ------\pkg_Core\Modules\LogManager\... ------\pkg_Core\Modules\PluginManager\... ------\pkg_Core\Modules\StringTable\... ------\pkg_Example\... ------\pkg_UnitTest\Interface\cppunit ------\pkg_UnitTest\Modules\TestCore ... .\Doc .\Doc\插件开发帮助.chm .\Doc\插件基础使用说明书.pdf

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧