std::string compare

输入提示:生成摘要

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#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,'\0',MAX_LIMIT); 
    std::cin.get(pChar,MAX_LIMIT); 
    while(!ComparePC2S(pChar,EXIT_STRING)) 
    { 
        std::cin.sync();//std::cin.ignore(MAX_LENGTH,'\0'); 
        std::cout << "Please enter your message: "; 
        memset(pChar,'\0',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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值