首页 > 其他 > 详细

std::string compare

时间:2014-03-09 06:34:06      阅读:347      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
#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; 
}; 
bubuko.com,布布扣

std::string compare,布布扣,bubuko.com

std::string compare

原文:http://www.cnblogs.com/hongjiumu/p/3588274.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!