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,'\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 ;
}; 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=;index<std::strlen(pChar);index++)
{
if(pChar[index]!=pCharTemp[index])
return false;
}
return true;
};
std::string compare的更多相关文章
- 源码阅读笔记 - 3 std::string 与 Short String Optimization
众所周知,大部分情况下,操作一个自动(栈)变量的速度是比操作一个堆上的值的速度快的.然而,栈数组的大小是在编译时确定的(不要说 C99 的VLA,那货的 sizeof 是运行时计算的),但是堆数组的大 ...
- c++ std::string 用法
std::string用法总结 在平常工作中经常用到了string类,本人记忆了不好用到了的时候经常要去查询.在网上摘抄一下总结一下,为以后的查询方便: string类的构造函数: string(co ...
- C++ std::unordered_map使用std::string和char *作key对比
最近在给自己的服务器框架加上统计信息,其中一项就是统计创建的对象数,以及当前还存在的对象数,那么自然以对象名字作key.但写着写着,忽然纠结是用std::string还是const char *作ke ...
- std::string 用法总结
标准C++中的string类的用法总结 相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有 ...
- std::string的find问题研究
https://files-cdn.cnblogs.com/files/aquester/std之string的find问题研究.pdf 目录 目录 1 1. 前言 1 2. find字符串 1 3. ...
- std::string 用法
string类的构造函数:string(const char *s); //用c字符串s初始化string(int n,char c); //用n个字符c初始化 string类的字符操作:const ...
- C++手稿:std::string
字符串在非常多编程语言中已经成为基本数据类型,C语言中我们使用char*来手动申请和维护字符串, 在C++中,能够使用std::string来方便地创建和操作字符串. string是一个模板类.它有b ...
- std::string类详解
之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必 担心内存是否足够.字符串长度等等,而且作为一个类出现,他集成的操作函数足以完成我们大多数情况下(甚至 ...
- C# CompareTo 和 String.Compare
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
随机推荐
- Tutorial 3: Class-based Views
转载自:http://www.django-rest-framework.org/tutorial/3-class-based-views/ Tutorial 3: Class-based Views ...
- django 项目中的 favicon.ico 处理
django 项目中的 favicon.ico 处理 (django == 2.0.6) 1. 引入模块: from django.views.generic.base import Redirec ...
- PCA算法和SVD
如果矩阵对某一个向量或某些向量只发生伸缩变换,不对这些向量产生旋转的效果,那么这些向量就称为这个矩阵的特征向量,伸缩的比例就是特征值.这里可以将特征值为负,特征向量旋转180度,也可看成方向不变,伸缩 ...
- plt-3D打印1
plt-3D打印 import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D ...
- Expert C Programming 阅读笔记(CH2)
P33 Bugs are by far the largest and most successful class of entity, with nearly a million known ...
- 1-4 TCP/IP协议族
网络协议是在内核中实现的,socket是对tcp/ip协议的系统调用,提供以下两点功能: 1. 将应用撑血数据从用户缓冲区中复制到TCP/UDP内核发送缓冲区,以交付内核发送来的数据(比如send), ...
- javascript copy text to clipboard
本段代码摘自微软docs网站上,目前需要解决在IE浏览器中触发copy事件的方法,也可以直接调用jquery. <!DOCTYPE html> <html> <head& ...
- spectre漏洞代码分析-c代码
下面一句话转自360: 现代处理器(CPU)的运作机制中存在两个用于加速执行的特性,推测执行( Speculative Execution)和间接分支预测(Indirect Branch Predic ...
- 提起Ajax请求的方式(POST)
前言 => 是ES6中的arrow function x=>x+6 就相当于 function(x){ return x+6; } 正文 XMLHttpRequest a=new XMLH ...
- [Gym - 100517K] Kingdom Division 2 二分
大致题意: 给出一个凸包,以及凸包内的两个点p1,p2,求有多少条经过凸包顶点的直线能够将凸包分割为两部分,且给出的两点分别属于不同的部分 枚举凸包的顶点,二分求出p1,p2线段左边的最大坐标L以及右 ...