#include <iostream>
#include <assert.h>
using namespace std;
//模拟实现strcmp函数。 bool my_strcmp(const char *str1,const char *str2)
{
assert(str1!=NULL && str2!=NULL);
const char *p = str1;
const char *q = str2;
while (*p != '\0' && *q != '\0' && *p == *q)
{
p++;
q++;
}
return (*p - *q)!=0;
}
int main()
{
cout << my_strcmp("liwu", "liu") << endl;
return 0;
} #include <iostream>
#include <assert.h>
using namespace std;
//库函数memcopy的实现。
char *my_memcopy(char *dist, const char *src, int len)
{
assert(dist != NULL && src != NULL);
char *p = dist;
int n = len>(strlen(src)+1) ? strlen(src)+1 : len;
while (n-->0)
{
*dist++ = *src++;
}
return p;
}
int main()
{
char s1[20] = "1234";
my_memcopy(s1,"liuhuiyan",2);
cout << s1 << endl;
} #include <iostream>
#include <assert.h>
using namespace std;
char* my_memove(char *dist,const char* src,int len)
{
assert(dist!=NULL && src!=NULL);
char *p = dist;
const char *q = src; int n = len>(strlen(src) + 1) ? strlen(src) + 1 : len;
if (p <= q || q+n<=p)
{
while (n-- > 0)
{
*p++ = *q++;
}
}
else
{
p += n-1;
q += n-1;
while (n-- > 0)
{
*p-- = *q--;
}
}
return dist;
}
int main()
{
char s1[] = "liu hui yan";
char s2[] = "123 456";
cout << my_memove(s1, s2, 6) << endl;
return 0;
} #include <iostream>
using namespace std;
//一个字符串“student a am i”,现要求将这个字符串改动为“i am a student”。
void exchange(char *p1,char *p2)
{
char temp;
while (p1 < p2)
{
temp = *p1;
*p1 = *p2;
*p2 = temp;
p1++;
p2--;
}
}
char* my_exchange(char *src)
{
char *p = src;
char *q = src;
while (*p != '\0')
{
while (*p != ' ' && *p!='\0')
{
p++;
}
exchange(q,p-1);
if (*p == '\0')break;
p++;
q = p;
}
exchange(src,p-1);
return src;
}
int main()
{
char s[] = "student a am i";
cout << my_exchange(s) << endl;
} //字符串打印数字。
#include <iostream>
#include <assert.h>
using namespace std;
int my_int(const char *str)
{
assert(str!=NULL);
int count = 0;
while (*str != '\0')
{
count = (count * 10 + *str - '0');
str++;
}
return count;
}
int main()
{
char s[] = "12345";
cout << my_int(s) << endl;
return 0;
}
#include <iostream>
using namespace std;
char str[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
//输入数字1234,打印对应的字符串。 void Printf(int x)
{ if (x==0)return;
else
{
Printf(x / 10);
cout << str[x % 10] << endl;
} }
int main()
{
Printf(1234);
return 0;
}

C++字符串操作二的更多相关文章

  1. python 字符串操作二 内建函数

    一.查看字符串的内建函数 >>> dir(str) ['__add__', '__class__', '__contains__', '__delattr__', '__dir__' ...

  2. [Redis-CentOS7]Redis字符串操作(二)

    登录Redis # redis-cli 127.0.0.1:6379> 添加字符串 EX 超期时间60s 127.0.0.1:6379> set username 'leoshi' OK ...

  3. 【二】php 字符串操作及三大流程控制

    字符串操作: trim:去除字符串开始位置和结束位置的空格 ltrim:去除开始处的空格 rtrim:去除结束处的空格 strtoupper:将字符串转换为大写 strtolower:将字符串转换为小 ...

  4. python基础(二)-- 列表、字典、集合、字符串操作

    4.列表: 基本操作: 索引 切片 追加 删除 长度 切片 循环 包含 import copy i=0 #persons=['dailaoban','xiekeng',['age',100,50],' ...

  5. java 字符串操作和日期操作

    一.字符串操作 创建字符串 String s2 = new String("Hello World"); String s1 = "Hello World"; ...

  6. C语言字符串操作总结大全

    1)字符串操作 strcpy(p, p1)  复制字符串  函数原型strncpy(p, p1, n)   复制指定长度字符串  函数原型strcat(p, p1)   附加字符串  函数原型strn ...

  7. c# 字符串操作

    一.字符串操作 //字符串转数组 string mystring="this is a string" char[] mychars=mystring.ToCharArray(); ...

  8. C语言字符串操作总结大全(超详细)

    本篇文章是对C语言字符串操作进行了详细的总结分析,需要的朋友参考下 1)字符串操作  strcpy(p, p1) 复制字符串  strncpy(p, p1, n) 复制指定长度字符串  strcat( ...

  9. linux shell 字符串操作

    转:http://justcoding.iteye.com/blog/1963463 在做shell批处理程序时候,经常会涉及到字符串相关操作.有很多命令语句,如:awk,sed都可以做字符串各种操作 ...

随机推荐

  1. springboot添加外部jar包及打包

    项目中除了从pom中添加依赖包,还可以添加本地的jar包,怎么做呢? 1.在src下新建目录lib,将jar包添加到lib中 2.在pom文件里添加配置以下属性,就可以使用jar包了 <depe ...

  2. 【Luogu】P3355骑士共存问题(最小割)

    题目链接 像题面那样把棋盘染成红黄点.发现骑士迈一步能到达的点的颜色一定是跟他所在的格子的颜色不同的.于是(woc哪来的于是?这个性质有这么明显吗?)从源点向所有红点连边,从所有黄点向汇点连边,红点向 ...

  3. 【SCOI2003】【BZOJ1092】蜘蛛难题

    有一堆管道,还有一个蜘蛛Willy,如下图所示.所有管道的是上端开口,下端封底,直径都是1cm,连接两个管道的连接容量无限,但体积可以忽略不计. 在第一个管道上方有一个水源,从中有水不断往下流,速度为 ...

  4. testng依赖

    Testng提供了两种依赖实现 1.强制依赖:某个测试用例之前需要执行的依赖链中如果有一个失败,那么接下来所有的测试都不会被执行 2.顺序依赖(软依赖):顺序依赖的用处更多是用来检测一个测试链是否按照 ...

  5. Redis Cluster 集群的实现和管理

    系统环境 CentOS 7 集群规划 在一台物理机(实际部署应当分散到多个物理机上),创建6个Redis节点,其中3个主节点.3个从节点. 节点表: IP 端口 主从 路径 192.168.1.21 ...

  6. Yii框架Yiiapp()的理解

    Yii::app() 是一个实例化的对象,是我们在当前框架里边可以直接操作的对象,        我们可以把这个对象理解成请求应用的第一个对象. Yii框架是纯OOP面向对象框架,也就是利用对象调用类 ...

  7. js库-AngularJS

    我是一个不思进取的前端. 我想按部就班的工作. 我想得过且过. 老天呀!你咋又逼迫我学习对于我来说的新知识呢!!!!!!!我想哭呀!!!!! 在某个代码项目中我看到了{{??}}这么个标记!我的神呀! ...

  8. VUE之Router命令行警告:Named Route 'Home' has a default child route. 解决办法

    Named Route 'Home' has a default child route. When navigating to this named route (:to="{name: ...

  9. HDU 5790 Prefix(Hash + 主席树)

    题目链接  Prefix 题意  给定一个字符串序列,求第$l$个字符串到第$r$个字符串之间有多少个不同的前缀 强制在线 考虑$Hash$ 首先把所有前缀都$hash$出来,按顺序组成一个长度不超过 ...

  10. ajax跨域-springboot

    package com.xxxx.xx.service.configuration; import org.springframework.context.annotation.Bean; impor ...