String 类的函数实现
#include<iostream>
//#include<string>
using namespace std; class Strings
{
public:
Strings(const char * str=NULL); Strings(const Strings &another);
~Strings();
Strings & operator=(const Strings &ths);
private:
char *m_data;
};
Strings::Strings(const char *str)
{
if(str==NULL)
{
m_data=new char[];
m_data[]='\0';
}
else
{
m_data=new char[strlen(str)+];
strcpy(m_data,str);
} }
Strings::Strings(const Strings &another)
{
m_data=new char[strlen(another.m_data)+];
strcpy(m_data,another.m_data );
}
Strings::~Strings()
{
delete [] m_data;
} Strings &Strings::operator=(const Strings &ths)
{
if(this==&ths)
return *this;
delete[]m_data;
m_data=new char[strlen(ths.m_data)+];
strcpy(m_data,ths.m_data);
return *this;
}
int main()
{
Strings a("abcdefg");
printf("%s\n",a);
Strings b(a);
printf("%s\n",b);
Strings c=b;
printf("%s\n",c);
system("pause");
return ; }
String 类的函数实现的更多相关文章
- string类find函数返回值判定
string类find函数返回值判定 代码示例 #include<iostream> #include<cstring> using namespace std; int m ...
- C++string类常用函数
C++string类常用函数 string类的构造函数:string(const char *s); //用c字符串s初始化string(int n,char c); //用n个字符c初 ...
- C++ string类及其函数的讲解
文章来源于:http://www.cnblogs.com/hailexuexi/archive/2012/02/01/2334183.html C++中string是标准库中一种容器,相当于保存元素类 ...
- String 类的实现(3)String类常用函数
2 #include<iostream> 3 #include<stdio.h> 4 #include<assert.h> 5 #include <iom ...
- 洛谷 P1308 统计单词数【string类及其函数应用/STL】
题目描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数. 现在,请你编程实现这一功能,具体要求是:给定一个单词,请你输出它在给 ...
- 【Java】整理关于java的String类,equals函数和比较操作符的区别
初学 Java 有段时间了,感觉似乎开始入了门,有了点儿感觉但是发现很多困惑和疑问而且均来自于最基础的知识折腾了一阵子又查了查书,终于对 String 这个特殊的对象有了点感悟大家先来看看一段奇怪的程 ...
- String 类 常用函数
构造方法摘要: String(byte[] bytes) 通过使用平台的默认字符集解码指定的 byte 数组,构造一个新的 String. String(char[] value) ...
- 新手C#string类常用函数的学习2018.08.04
ToLower()用于将字符串变为小写,注意字符串的不可变特性,需要重新赋值给另一个字符串变量. s = s.ToLower();//字符串具有不可变性,转换后需要重新赋值,不可仅有s.ToLower ...
- HDU——2093考试排名(string类及其函数的运用以及istringstream)
考试排名 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
随机推荐
- 9.2.1、Libgdx的输入处理之轮询
(官网:www.libgdx.cn) 轮询是检测输入设备的当前状态,比如特定的按键按下,屏幕第一个手指的位置等等.这是一个快速简单的处理用户输入的方式,并且应用到很多的游戏中. 注意:如果你处理轮询, ...
- Linux Shell 命令--tr
tr 用来从标准输入中通过替换或删除操作进行字符转换 -c或--complerment 取代所有不属于第一字符集的字符. -d ...
- How Many Processes Should Be Set For The Receiving Transaction Manager (RTM)
In this Document Goal Solution References APPLIES TO: Oracle Inventory Management - Version 10 ...
- spring 注解模式 详解
Spring基于注解实现Bean定义支持如下三种注解: Spring自带的@Component注解及扩展@Repository.@Service.@Controller,如图12-1所示: JSR-2 ...
- 理解WebKit和Chromium: Chromium网络栈
转载请注明原文地址:http://blog.csdn.net/milado_nju ## 概述 前面讲到Chromium的资源加载机制,在调用栈上,提到URLRequest之后就戛然而止,在这之下就是 ...
- python-inotify 在linux上安装
python-inotify 在linux上安装 0 下载 $ wget --no-check-certificate https://pypi.python.org/packages/source/ ...
- Matlab R2013a: C++ MEX on Ubuntu 14.04 64-bit
原文地址: http://blogs.bu.edu/mhirsch/2013/07/matlab-r2013a-mex-on-ubuntu-13-04-64-bit/ Note: the way Me ...
- linux下用gtk+写比赛赌博GUI小游戏
游戏界面全部由gtk的GUI完成,没有使用openGL之类的高端货. 游戏玩法就是8位选手比赛跑步,你可以在赛前赌哪位选手会赢,如果输了cash会被扣除,反之cash会增加. 无聊写了3个选项:小数时 ...
- Linux基础正则表达式字符汇整(characters)
RE 字符 意义与范例 ^word 意义:待搜寻的字串(word)在行首! 范例:搜寻行首为 # 开始的那一行,并列出行号 grep -n '^#' regular_express.txt word$ ...
- linux下64位汇编的系统调用(4)
经过上一篇的铺垫貌似可以很轻松的用汇编写出mmap的代码来,可仔细一看,还是有不少问题需要解决: 1.系统调用mmap如果出错并不直接返回MAP_FAILED(-1),而是一个"类似&quo ...