Home > Back-end >  New c, seek help from god
New c, seek help from god

Time:10-06

//myString. H
# pragma once
#include
using namespace std;
The class myString
{
Char * _mystring;
Public:
MyString (const char * STR);
MyString (const myString& Str1, const myString& Str2);
MyString (const int len);
~ myString (void);
Friend ostream & amp; Operator<(ostream & amp; , const myString & amp;);
Friend myString operator + (const myString& Str1, const myString& Str2);
Const int the count () const;
Const char & amp; Operator [] (unsigned short offset) const;
};

//myString. CPP
# include "myString. H"
#include
MyString operator + (const myString& Str1, const myString& Str2)
{
MyString temp (str1, str2);

return temp;
}
Ostream & amp; Operator<(ostream & amp; Out, const myString & amp; STR)
{
for(int i=0; i{
Out}
Return the out;
}
MyString: : myString (const char * STR)
{
_mystring=new char [strlen (STR) + 1);
Strcpy (_mystring, STR);
}

MyString: : myString (const int len)
{
_mystring=new char (len);
Memset (_mystring, 0, len);

}

MyString: : myString (const myString& Str1, const myString& Str2)
{
_mystring=new char [str1. The count () + str2. The count ()];
for(int i=0; i{
_mystring [I]=str1 [I];
}
for(int j=0; j{
_mystring [str1. The count () + j]=str2 [j];
}
}

MyString: : ~ myString (void)
{

}

Const const int myString: : the count ()
{
Return strlen (_mystring);

}
How to spend the rest of the
Friend ostream & amp; Operator<(ostream & amp; , const myString & amp;);
Friend myString operator + (const myString& Str1, const myString& Str2);
These two functions written ah, see the online good mystring class writing, look not to understand ah, the teacher taught for two days, c + + doesn't ah

CodePudding user response:

Suggest you look for c + + book, see part operator overloading,
Post the final, to vote for me , thank you.

CodePudding user response:

The problem is that the teacher taught us two days shall we write something, don't, and hand in your homework soon, and book look not to understand ah

CodePudding user response:

The problem is that the teacher taught us two days shall we write something, don't, and hand in your homework soon, and book look not to understand ah

CodePudding user response:

These two functions you don't have his stick out in front?

CodePudding user response:

reference 4 floor dataxdata response:
these two functions you don't have his stick out in front?

How do you write the two function body

CodePudding user response:

These are not your own post?
MyString operator + (const myString& Str1, const myString& Str2)
{
MyString temp (str1, str2);

return temp;
}
Ostream & amp; Operator<(ostream & amp; Out, const myString & amp; STR)
{
for(int i=0; i{
Out}
Return the out;
}

CodePudding user response:

refer to the second floor baidu_18230133 response:
the problem is that the teacher, teach us two days shall we write something, don't, and hand in your homework soon, and books can't understand ah

Can you ask your teacher, he studied two days don't write it