分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
- //下面是一个检查一个字符串中是否有'.'的函数,该函数将找到的'.'转化为'_'。
- inline void checkName(string& name)
- {
- std::string::size_type startpos = 0;
- while (startpos!= std::string::npos)
- {
- startpos = name.find('.'); //找到'.'的位置
- if( startpos != std::string::npos ) //std::string::npos表示没有找到该字符
- {
- name.replace(startpos,1,"_"); //实施替换,注意后面一定要用""引起来,表示字符串
- }
- }
- }
本文转自:http://hi.baidu.com/bacel_chen/blog/item/e55e9b1a5c7fdc108618bfe2.html
关于std::string::npos,有说是-1,也有说无穷大数,众说纷纭,总之,用来判断字符串中是否包含指定字符串.
给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
![这里写图片描述](https://i-blog.csdnimg.cn/blog_migrate/2e19ffb3303a490d20ea5d00dd397156.gif)