简体   繁体   English

C++比较两个字符串坏代码

[英]C++ compare two strings bad code

I have problem with my code.. i dont know what is wrong.. I need compare two strings.我的代码有问题.. 我不知道出了什么问题.. 我需要比较两个字符串。 Error message: error:'outputFile' does not name a type.错误消息:错误:'outputFile' 未命名类型。

I am working with files.. write some text into it... My code for compare:我正在处理文件......在其中写入一些文本......我的比较代码:

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

Function:功能:

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;
}

It is working separately and when i delete for cycle from main function, all is working.. I dont know how to solve this problem..它单独工作,当我从主函数中删除循环时,一切正常..我不知道如何解决这个问题..

In fact i need just compare if value at index i compare to "mzda"事实上,我只需要比较索引处的值是否与“mzda”进行比较

edit:编辑:

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

I dont think error is here.. (this code is under for).我不认为这里有错误..(这段代码是用于)。 When i delete for all is working当我删除所有工作时

Correct one.正确一个。 And please ask in google "std string compare ignore case".请在谷歌中询问“标准字符串比较忽略大小写”。

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM