当前位置:网站首页>STL string输入输出重载2
STL string输入输出重载2
2022-07-17 15:12:00 【joker_0030】
1、自定义头文件(Mystring.h)
//#pragma once
#ifndef _MYSTRING
#define _MYSTRING
#include<iostream>
using namespace std;
class stu
{
private:
//字符串首地址
char* m_str;
//字符串个数
size_t m_l;
public:
stu();//无参构造。
stu(size_t length ,char ch);//将length个字符ch,赋值进对象。
stu(const char* str);//用字符串给对象初始化
stu(const char* str,size_t length);//用一个字符的前length个长度进行赋值
stu(stu& str,size_t index,size_t length);//将另一个对象的中间一段字符串复制进当前对象
stu(const stu& str);//拷贝构造
public:
//得到字符串首地址。
const char* c_str() const;
//得到字符串的字符个数。
const size_t size() const;
//设置字符个数。
void s_l(size_t length);
//设置字符串内容。
char* &GetMstr();
public:
//析构函数
~stu();
public:
//输出重载
friend ostream& operator <<(ostream& os, stu& str);
//输入重载
friend istream& operator >>(istream& is, stu& str);
};
//输出重载
ostream& operator <<(ostream& os, stu& str);
//输入重载
istream& operator >>(istream& is, stu& str);
#endif
边栏推荐
猜你喜欢
随机推荐
Leetcode 1304. N different integers with zero and
Swift 二进制数据与16进制字符串的相互转换
ZABBIX proxy server configuration
Leetcode 1252. Number of odd value cells
Mpu9250 ky9250 attitude, angle module and mpu9250 MPL DMA comparison
Leetcode 1252. 奇数值单元格的数目
传输层 -------- TCP(一)
Round table record: fireside dialogue -- how to realize innovation in Web3
Limit query of MySQL optimization series
TiKV 线程池性能调优
[binomial tree] the power of the button cattle customers must brush questions
下推计算结果缓存
A current List of AWESOME Qt and qml
The type of MySQL index (single column index, combined index, BTREE index, clustered index, etc.)
【无标题】cv 学习1转换
02-2. Default parameters, function overloading, reference, implicit type conversion, about error reporting
Huawei firewall authentication technology
02-3. Difference between pointer and reference
Send blocking, receive blocking
Docker install MySQL









