c++,调用字符串是否相等的时候,打印看是相等的中文字符,但是两者还是不相等,是因为多了一个隐藏的换行符

打印十六进制,查看,多了一个d

打印十六进制 : std::hex
fade8bdb4d
fade8bdb4

    for (int i =0;i "<< detect_label[i].asString() <<"," << img_det_label[j]<< std::endl;
            std::string s1 = img_det_label[j];
            std::string s2 = detect_label[i].asString();

            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;

            std::cout << "---s2----" << s2 << std::endl;

            for(int pp = 0; pp < s2.size(); pp++) {
                int character = int(s2[pp]); // converting each character to its ascii value 
                std::cout << std::hex << character; // basefield is now set to hex
            }
            std::cout << std::endl;

            // if (s1.compare(s2) == 0) {
            
            if (s1==s2) {
                std::cout << "相等" << std::endl;
            } else {
                std::cout << "否" << std::endl;
            }
}            
在字符添加的时候,可以增加两句话

    std::string s1 = "小猫";  // 获取字符串
    
    // 删除不可见字符
    s1.erase(std::remove(s1.begin(), s1.end(), '\r'), s1.end());  // 空格
    s1.erase(std::remove(s1.begin(), s1.end(), '\n'), s1.end());  // 换行符

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