C++实例 MySTLString

Posted codeworkerliming

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++实例 MySTLString相关的知识,希望对你有一定的参考价值。

#include <iostream>
#include <cstring>
#include <string>
using namespace std;

class MySTLString

	public:
		MySTLString();
		MySTLString(int count, char ch);
		MySTLString(const char* s);
		const char& front() const;
		const char& back() const;
		int size() const;

	private:
		char* data_;
;

MySTLString :: MySTLString() : data_(new char[1])

	*data_ = ‘\0‘;



MySTLString :: MySTLString(const char* s) : data_(new char[strlen(s) + 1])

	strcpy(data_, s);


const char& MySTLString::front() const

	return data_[0];


int MySTLString::size() const

	return strlen(data_);


int main(void)

	MySTLString str("Hello");
	cout << str.front() << endl;
	cout << str.size()<<endl;

	return 0;

  

以上是关于C++实例 MySTLString的主要内容,如果未能解决你的问题,请参考以下文章

C++ 新运算符。创建新实例

将 Python 类实例传递给 C++ 函数

创建实例的 C++ 接口问题

c++实例化一个对象

在c++中,接口能实例化吗?下面是接口实例化吗?operFactory是啥?我初学。

如何使用 QJSEngine 实例化 c++ 对象