c++string字符串比较相等

#include 
#include 
#include 
using namespace std;

int main()
{
   
	 std::string h2 = "BUS_0001";
     std::string h3 = "BUS_0001";
	 printf(" h3 == h2: %d\n",h3 == h2);
	 
     if(h3 == h2) 
	{
		printf("true\n");
	 }else{
		printf("false\n");
     }
	
	printf("h3 compare h2: %d\n",h3.compare(h2));
	
	int flag = h3.compare(h2);
	if(flag == 0)
	{
		printf("true\n");
	}else{
		printf("false\n");
	 }
			
   return 0;
}

 h3 == h2: 1
true
h3 compare h2: 0
true
 

你可能感兴趣的:(c++)