C + + string Manipulation II

Source: Internet
Author: User

#include <iostream>#include <assert.h>using namespace STD;The simulation implements the STRCMP function.

BOOLMY_STRCMP (Const Char*STR1,Const Char*STR2) {assert (Str1!=null && str2!=null);Const Char*p = str1;Const Char*q = str2; while(*p! =' + '&& *q! =' + '&& *p = = *q) {p++; q++; }return(*p-*q)! =0;}intMain () {cout<< my_strcmp ("Liwu","Liu") << Endl;return 0;}#include <iostream>#include <assert.h>using namespace STD;//library function Memcopy implementation. Char*my_memcopy (Char*dist,Const Char*SRC,intLen) {assert (dist! = NULL && src! = null);Char*p = dist;intn = len> (strlen(SRC) +1) ?

strlen(SRC) +1: Len; while(n-->0) {*dist++ = *src++; }returnP;}intMain () {Chart1| -] ="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,intLen) {assert (Dist!=null && src!=null);Char*p = dist;Const Char*q = src;intn = len> (strlen(SRC) +1) ?strlen(SRC) +1: Len;if(P <= Q | | q+n<=p) { while(n-->0) {*p++ = *q++; } }Else{p + = n1; Q + = n1; while(n-->0) {*p--= *q--; } }returnDist;}intMain () {CharS1[] ="Liu Hui Yan";CharS2[] ="123 456";cout<< my_memove (S1, S2,6) << Endl;return 0;}#include <iostream>using namespace STD;//A string, "Student A Am I", is now required to change the string to "I am a student". voidExchangeChar*P1,Char*P2) {CharTemp while(P1 < P2) {temp = *P1; *P1 = *P2; *P2 = temp; p1++; p2--; }}Char* My_exchange (Char*SRC) {Char*p = src;Char*q = src; while(*p! =' + ') { while(*p! ="'&& *p!=' + ') {p++; } Exchange (q,p-1);if(*p = =' + ') Break; p++; Q = p; } Exchange (src,p-1);returnSRC;}intMain () {CharS[] ="Student A Am I";cout<< My_exchange (s) << Endl;}//String to print the number. #include <iostream>#include <assert.h>using namespace STD;intMy_int (Const Char*STR) {assert (str!=null);intCount =0; while(*str! =' + ') {count = (count *Ten+ *str-' 0 '); str++; }returnCount;}intMain () {CharS[] ="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 + + string Manipulation II

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.