栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++处理txt文件常用功能方法

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++处理txt文件常用功能方法

1.当字符串中只有一对双引号,取引号里面的内容
//跳过第一个引号以前的字符,读下面字符,直到下一个引号前为止
int main()
{
        string source = "how are you = "nihao"";
        int pos_1 = source.find(""");
        int pos_2 = source.find_last_of(""");
        string dest  = "";
        dest = source.substr(pos_1 + 1 ,pos_2 - pos_1 - 1);
        //substr(t1,t2) //含义:从t1位置读取t2长度的字符串
        cout<<"dest = " < 
2.string替换所有指定字符串(C++) 

参考:[1]

  string&   replace_all_distinct(string&   str,const   string&   old_value,const   string&   new_value)     
    {     
        for(string::size_type   pos(0);   pos!=string::npos;   pos+=new_value.length())   {     
            if(   (pos=str.find(old_value,pos))!=string::npos   )     
                str.replace(pos,old_value.length(),new_value);     
            else   break;     
        }     
        return   str;     
    }     
    int   main()     
    {       
        cout   <<   replace_all_distinct(string("12212"),"12","21")   <<   endl;     
    }     
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/698685.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号