字符串类构造函数 [英] String Class Constructors

查看:120
本文介绍了字符串类构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的赋值要求我们创建一个用户定义的字符串类,而不使用目录string.h,string或cstring中的任何内容。


但是在实现文件中我们' '给出,有两种不同形式的构造函数。

展开 | 选择 | Wrap | 行号

解决方案

C字符串以终止空字符''\0''结束。这个特殊字符的ASCII码是0.程序(意思是编译器)可以告诉构造函数之间的区别,因为参数不同。


要比较两个不同的字符串,首先是需要看看它们是否长度相同。然后你可以检查所有字符是否相同。


但是每个构造函数内部的代码到底是怎么回事?我对第一个构造函数的了解有多近?


我仍​​然不确定如何构造c-type。

类似于

展开 | 选择 | Wrap | 行号


好吧,我的构造函数更新......第一个(复制现有的String)看起来没问题,但我仍然不确定C样式构造函数。

展开 | 选择 | Wrap | 行号

Our assignment calls for us to create a user defined string class, without using anything from the directories string.h, string, or cstring.

however in the implementation file we''re given, there are two different forms of the constructor.

Expand|Select|Wrap|Line Numbers

解决方案

A C-string is ended by a terminating null character, ''\0''. The ASCII code for this special character is 0. The program (meaning the compiler) can tell the difference between the constructors because the parameters are different.

To compare two different strings, you first need to see if they are the same length. Then you can check if all the characters are the same.


but how exactly does the code for the inside of each constructor go? How close am I on understanding the first constructor?

I''m still unsure on how to construct the c-type.
something like

Expand|Select|Wrap|Line Numbers


alright, update on my constructors...The first one (copy existing String) looks okay, but I''m still unsure on the C-style constructor.

Expand|Select|Wrap|Line Numbers


这篇关于字符串类构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆