#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. 解决11g r2,12c使用wm_concat报错问题

    创建type CREATE OR REPLACE TYPE zh_concat_im AUTHID CURRENT_USER AS OBJECT ( CURR_STR ), STATIC FUNCTI ...

  2. iOS粒子效果

    网址链接:http://www.cocoachina.com/bbs/read.php?tid-103257.html http://code.cocoachina.com/view/125060 粒 ...

  3. 【Luogu】P3311数数(AC自动机上DP)

    题目链接 蒟蒻今天终于学会了AC自动机,感觉很稳 (后一句愚人节快乐) 这题开一个f[i][j][k]表示有没有受到限制,正在枚举第j位,来到了AC自动机的第k个节点 的方案数 随后可以刷表更新 注意 ...

  4. UGUI 点击穿透问题

    unity上 用 做游戏欢迎界面上通用的ui,然后导到游戏里面直接用,但发现游戏里面是用ngui的,点击ugui 的ui 会穿透过去 ngui会响应,原本模型的点击处理也会响应 我用的 unity 版 ...

  5. tyvj 2020 rainbow 的信号

    期望 被精度坑惨的我 注意:能开 long long 尽量开, 先除后乘, int 转 double 的时候 先转换在做运算 本题与位运算有关,位与位之间互不影响,所以我们可以分开考虑 #includ ...

  6. 【BZOJ4472】salesman(树形DP)

    题意: 给定一颗有点权的树,每个树上的节点最多能走到lim[u]次,求一条路径,使路径上的点权和最大,每个节点上的点权如果走了多次只能算一次.还要求方案是否唯一. 思路:每个点只能取lim[u]-1个 ...

  7. 转 如何在C++中调用C程序

    如何在C++中调用C程序?   C++和C是两种完全不同的编译链接处理方式,如果直接在C++里面调用C函数,会找不到函数体,报链接错误.要解决这个问题,就要在 C++文件里面显示声明一下哪些函数是C写 ...

  8. 转 Python——UnicodeEncodeError: 'ascii' codec can't encode/decode characters

    转自: http://blog.csdn.net/zuyi532/article/details/8851316 我是写爬虫的时候遇到的问题,百度了一下,先贴解决方案: 在代码中加入: import ...

  9. 细说Redis监控和告警

    https://blog.csdn.net/qq_27623337/article/details/53206685

  10. AC日记——[USACO09JAN]全流Total Flow 洛谷 P2936

    题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...