我的学习记录33

来源:互联网 发布:gta5亚洲美女捏脸数据 编辑:程序博客网 时间:2024/05/21 21:02

2017.11.12李锦浩【第33天】

今天练习了编辑文本的程序练习,面对关于字符串的练习,我已经有了比较深刻的了解和应用。另外我今天还学了关于链表的相关知识,知道了链表里的结点可以用于连接其他数组的一种有效的方式,但是我对其中的一些具体的操作方式还不是很了解,明天要继续学习。

附:编辑文本程序练习:

//biaotou.h

#pragma once

#include<iostream>

#include<string>

#include<cstdio>

using namespace std;

void charu(string &s,string &t)

{

         cout << "请选择插入目标,1表示插入至某一个字符前,2表示插入至某段之前"<< endl;

         int x,y;

         cin >> x;

         if (x == 1)

         {

                  cin >> y;

                  cout << "请输入所要插入的字符序号"<< endl;

                  t.insert(y, s);

                  cout << s << endl;

         }

         if (x == 2)

         {

                  t += s;

                  cout << t << endl;

         }

}

void shanchu(string &s)

{

         cout << "请选择需要删除的字符数量,1表示删除所有,2表示删除一定数量"<< endl;

         int x, y;

         cin >> x;

         if (x == 1)

         {

                  cout << "请选择是否返回,1表示返回,2表示不返回"<< endl;

                  cin >> y;

                  if (y == 1)

                  {

                          s.erase();

                  }

                  if (y == 2)

                  {

                          s.clear();

                  }

         }

         if (x == 2)

         {

                  cout << "请选择删除字符的数量以及删除起始对象"<< endl;

                  int z;

                  cin >> y>>z;

                  s.erase(z, y);

         }

         cout << s << endl;

}

void tihuan(intt, int m, string &s,string a)

{

         s.replace(t,m, a);

}

void chazhao(string &s)

{

         cout << "请输入查找对象"<< endl;

         char *c;

         c = new char[64];

         gets_s(c, 64);

         string s1;

         s1 = c;

         s.find(s1);

         delete []c;

         c = NULL;

}

//yuan.cpp

#include<iostream>

#include"标头.h"

#include<cstdio>

using namespace std;

int main()

{

         cout << "请输入文本"<< endl;

         char *b;

         b = new char[500];

         gets_s(b, 500);

         string s;

         s = b;

         cout << "请选择对文本的操作,1表示插入,2表示删除,3表示替换,4表示查找,5退出程序"<< endl;

         int x;

         cin >> x;

         if (x == 1)

         {

                  cout << "请输入插入对象"<< endl;

                  char *a;

                  string s1;

                  a = new char[20];

                  gets_s(a, 20);

                  s1 = a;

                  charu(s, s1);

                  delete[]a;

                  a = NULL;

         }

         if (x == 2)

         {

                  shanchu(s);

         }

         if (x == 3)

         {

                  cout << "请输入替换的目标区域,以及替换的内容"<< endl;

                  int t, m;

                  cin >> t >> m;

                  char*a;

                  a = new char[20];

                  gets_s(a, 20);

                  tihuan(t, m, s, a);

         }

         if (x == 4)

         {

                  chazhao(s);

         }

         if (x == 5)

         {

                  return 0;

         }

         system("pause");

         return 0;

}

明日任务:继续复习前面知识,尝试做一个自己想的程序,继续学习链表。

原创粉丝点击