-4

何らかの理由で、以下のこのC++はfalseを返し続けます。どんな助けでも認められるでしょう!より多くのソースを含めますが、LibPQにあります

std::string one = "stringa";
std::string two = "stringb";

std::string three = "stringa";
std::string four = "stringb";

if( one.compare( three ) == 0 && two.compare( four ) == 0 )  {

  return true;
} else {

  return false;
}
4

3 に答える 3

0

やってみました:

std::string one = "stringa";
std::string two = "stringb";

std::string three = "stringa";
std::string four = "stringb";

if( one == three && two == four ) {

  return true;
} else {

  return false;
}
于 2013-01-04T08:23:07.387 に答える
0

問題は、ifの後に{がないことです。これを試して

std::string one = "stringa";
std::string two = "stringb";

std::string three = "stringa";
std::string four = "stringb";

if( one.compare( three ) == 0 && two.compare( four ) == 0 )
{
  return true;
} else {

  return false;
}

ところで、あなたのコードはそれに準拠していますか?

于 2013-01-04T08:25:57.327 に答える
0

以下のようなものを試すことができます:

#include "iostream" 

using namespace std; 

std::string one = "amit"; 
std::string two = "kumar"; 
std::string three = "amit"; 
std::string four = "kumar"; 

bool strcomp() 
{ 
    if (one.compare(three) == 0 && two.compare(four) == 0) 
    { 
        return true; 
    } 

    return false; 
} 

int main() 
{ 
    if (strcomp()) 
    { 
       cout<<"Equal"<<endl; 
    } 
    else 
    { 
       cout<<"Defferent"<<endl; 
    } 

} 

出力:等しい

于 2013-01-04T08:35:16.300 に答える