c++比较字符串是否相等常用的方法compare或者==, 一个字符串在另一个数组中出现的次数,find或者count

   // 有两个方法,一个字符串找到数组中所有字符串是否有相等的个数, std::count() std::find()
    for (int i =0;i<detect_label.size();i++){
        int count = std::count(img_det_label.begin(), img_det_label.end(), detect_label[i].asString());
        img_det_lab_num = img_det_lab_num + count ;

        
        if (std::find(img_det_label.begin(),img_det_label.end(),detect_label[i].asString()) != img_det_label.end()){  
            img_det_lab_num = img_det_lab_num + 1;
        } 
  
    }

c++中如果两个字符串打印相等,但是比较确不相等,可能有隐藏换行符空格等
打印十六进制,看一下,多了一个d,
fade8bdb4d
fade8bdb4

    std::string s1 = "小猫";  // 获取字符串
    std::cout << "---s1----" << s1 << std::endl;
    for(int pp = 0; pp < s1.size(); pp++) {
        int character = int(s1[pp]); // converting each character to its ascii value 
        std::cout << std::hex << character;
            // basefield is now set to hex
    }
    std::cout << std::endl;

    // 删除不可见字符
    s1.erase(std::remove(s1.begin(), s1.end(), '\r'), s1.end());
    s1.erase(std::remove(s1.begin(), s1.end(), '\n'), s1.end());

你可能感兴趣的:(c++,开发语言)