std::string compare

#include <iostream> 
  
#define NULL 0 
#define MAX_LIMIT 5 
//#define MAX_LENGTH 2 
  
bool ComparePC2S(const char *,const std::string &); 
  
int main() 
{ 
    const std::string EXIT_STRING="exit"; 
  
  
    std::cout<<"Over"<<std::endl; 
    char * pChar(NULL); 
    pChar=new char[MAX_LIMIT]; 
    memset(pChar,'',MAX_LIMIT); 
    std::cin.get(pChar,MAX_LIMIT); 
    while(!ComparePC2S(pChar,EXIT_STRING)) 
    { 
        std::cin.sync();//std::cin.ignore(MAX_LENGTH,''); 
        std::cout << "Please enter your message: "; 
        memset(pChar,'',MAX_LIMIT); 
        std::cin.get(pChar,MAX_LIMIT); 
    } 
    delete [] pChar; 
    return 0; 
}; 
  
bool ComparePC2S(const char * pChar,const std::string & str) 
{ 
    const char * pCharTemp=str.c_str(); 
    if(strlen(pChar)!=strlen(pCharTemp)) 
        return false; 
    int index; 
    for(index=0;index<std::strlen(pChar);index++) 
    { 
        if(pChar[index]!=pCharTemp[index]) 
            return false; 
    } 
    return true; 
}; 
原文地址:https://www.cnblogs.com/hongjiumu/p/3588274.html