• C++的一些应用


    切分函数

    void Tokenize(const string& str, vector& tokens, const string& delimiters)  // 切分函数
    {
        // Skip delimiters at beginning.
        string::size_type lastPos = str.find_first_not_of(delimiters, 0);
        // Find first "non-delimiter".
        string::size_type pos = str.find_first_of(delimiters, lastPos);
        while (string::npos != pos || string::npos != lastPos)
        {
            // Found a token, add it to the vector.
            tokens.push_back(str.substr(lastPos, pos - lastPos));
            // Skip delimiters.  Note the "not_of"
            lastPos = str.find_first_not_of(delimiters, pos);
            // Find next "non-delimiter"
            pos = str.find_first_of(delimiters, lastPos);
        }
    }

    引用该函数方法:

        string str(string类型);  
        vectortokens;
        Tokenize(str, tokens, "/"); 以“/”切分

    需要到得到切分后的第几个位置的参数方法:tokens[tokens.size() - 1]

        string last1 = tokens[tokens.size() - 1]; //倒数第一个参数
        string last2 = tokens[tokens.size() - 2]; //倒数第二个参数

    判断文件中是否有东西:

    src_test.size() == 0

    如果等于0则文件夹中无内容

    写日志:

    string log_path = "./log.txt"; // 的日志文件地址
    std::ofstream outfile(log_path); 

    in.open(log_path, std::ios::trunc); //打开日志文件进行写入

    in << "写入日志内容\n" << endl;
    in.close(); //关闭日志

    in.open(log_path, std::ios::trunc);
            in << "readNet not run!!!\n" << endl;
            in.close();
            return false;

    创建文件夹:

    if (_access(string类型.c_str(),  0) == -1)    //如果文件夹不存在
    {
       int re = _mkdir(imwrite_path3.c_str());                //则创建
    }

    该方法只能一层一层创建

    抛出异常:

    try{ 条件 :a!=b}

    catch{结果:可以continue+打印日志}

    引用头文件:

    #include “xxxx.h”

    ###########################################################################

    后续补充

  • 相关阅读:
    STM32 cubemx配置USART DMA传输
    13.1.X:ByteScout PDF Extractor SDK
    Springboot整合ShardingJdbc实现分库分表方案
    京能查干淖尔电厂电子汽车衡称重系统
    递归和排序算法的应用
    linux 时间和北京时间对不上
    解决mysql中group_concat长度限制的方案
    AI实战营第二期 第十节 《MMagic 代码课》——笔记11
    HTML5和HTML的区别
    大模型日报|今日必读的7篇大模型论文
  • 原文地址:https://blog.csdn.net/qq_49627063/article/details/126744104