C++比较两个字符串的错误代码

C++ compare two strings bad code

本文关键字:两个 字符串 错误代码 比较 C++      更新时间:2023-10-16

我的代码有问题。。我不知道怎么了。。我需要比较两根绳子。错误消息:错误:"outputFile"未命名类型。

我正在处理文件。。在里面写一些文本…我的比较代码:

for (int i = 0; i < size; i++){
            if (PorovnaniKategorie(ArrayOfWorlds[i],"mzda")==true){
//do some code
            }
            }
        }

功能:

bool PorovnaniKategorie(string s1, string s2){
    bool porovnani1=true;
    int vel1 = s1.size();
    int vel2 = s2.size();
if (vel1 == vel2)
                    {
                    for ( int i = 0; i < vel1; i++)
                    {
                        if(tolower(s1[i])!= tolower(s2[i]))
                           porovnani1 = false;
                          }
                    }
else{
    porovnani1 = false;
}
return porovnani1;
}

它是单独工作的,当我从主功能中删除循环时,一切都在工作。。我不知道如何解决这个问题。。

事实上,我只需要比较一下索引处的值是否与"mzda"相比较

编辑:

outputFile << "</body>" << endl;  //this line is error
        outputFile << "</html>" << endl;
        outputFile.close();

我不认为这里有错误。。(此代码位于的下方)。当我删除所有正在工作的时

更正一个。请在谷歌中询问"std字符串比较忽略情况"。

bool PorovnaniKategorie( string s1, string s2 )
{
    if( s1.size() == s2.size() ) {
        for( std::string::size_type i = 0; i < s1.size(); i++ ) {
            if( tolower( s1[i] ) != tolower( s2[i] ) ) {
                return false;
            }
        }
        return true;
    }
    return false;
}