#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. spl_autoload_register和__autoload

    1.实例化一个未定义的类时会触发 2.类存在继承关系时,被继承的类没有引入的情况下,会触发 (继承关系的两个类必须在同一个目录下)  __autoload 实例化PRINTIT类,'PRINTIT'作 ...

  2. 【转】[译]深入理解JVM

    http://www.cnblogs.com/enjiex/p/5079338.html 深入理解JVM 原文链接:http://www.cubrid.org/blog/dev-platform/un ...

  3. 论蛋疼的调戏matrix67的首页

    唔,初学js,然后拿matrix67的首页玩玩23333 console 里输入以下这句话 for(var i = 1; i <= 400; i++){var td = document.get ...

  4. 刷题总结——树有几多愁(51nod1673 虚树+状压dp+贪心)

    题目: lyk有一棵树,它想给这棵树重标号. 重标号后,这棵树的所有叶子节点的值为它到根的路径上的编号最小的点的编号. 这棵树的烦恼值为所有叶子节点的值的乘积. lyk想让这棵树的烦恼值最大,你只需输 ...

  5. jenkins配置发送邮件

    1.打开系统管理->系统设置,找到邮件设置,如下: 2.SMTP或者其他方式的发送邮件,可自行配置,一下列出了qq邮箱和163邮箱设置的地方,如下图: qq邮箱: 往下拉,找到如下图: 163邮 ...

  6. 洛谷 [P2886] 牛继电器Cow Relays

    最短路 + 矩阵快速幂 我们可以改进矩阵快速幂,使得它适合本题 用图的邻接矩阵和快速幂实现 注意 dis[i][i] 不能置为 0 #include <iostream> #include ...

  7. 转 C语言编译过程简介

    C语言编译过程简介 C语言编译过程简介 刚开始接触编程的时候,只知道照书敲敲代码,一直都不知道为什么在windows平台下代码经过鼠标那样点击几下,程序的结果就会在那个黑色的屏幕上.现在找了个机会将C ...

  8. dpkg --add-architecture i386 && apt-get update && > apt-get install wine32

    dpkg --add-architecture i386 && apt-get update &&> apt-get install wine32

  9. os.system() 和 os.popen()

    1.os.popen(command[, mode[, bufsize]])  os.system(command) 2.os.popen() 功能强于os.system() , os.popen() ...

  10. unorder_set<typename T> 学习

    转自http://blog.csdn.net/mmzsyx/article/details/8240071 散列容器(hash container): 通常比二叉树的存储方式可以提供更高的访问效率.# ...