Home > Back-end >  Use string c implementation of functions, but always appear error C2228: left of 'StringLength&
Use string c implementation of functions, but always appear error C2228: left of 'StringLength&

Time:09-19

The code is as follows:
# include
# include
# define Maxsize 50
using namespace std;

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

The class String//the String class
{
Public:
String ();//the constructor initialized ()
~ the String ();//the destructor (recycling)
Void CreateString ();//create a string of
Void ShowString ();//display string
Void the Modify (int place_1, int place_2, char str2 [20]);//modify the string
Void Insert (int place_3, char str3 [20]);//insert string
Void the Delete (int place_4, int place_5);//delete the substring
Void FindString (char str4 [20]);//search string
Int StringLength ();//long string
Private:
Char * Str;
Int Length;
};

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

String: : String ()
{
Str=new char [Maxsize];
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

String: : ~ String ()//destructor (recycling)
{
The delete [] Str;
Cout<& lt;" The list has been deleted "& lt; }

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Void String: : CreateString ()//create a String of
{
int i=0;
char ch;
While (ch=getchar ()!=(EOF)
{
If (ch!=13)
Cin. Get (Str [I]);
i++;
}
Length=I;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Void String: : ShowString ()
{
int i;
If (Length<=0)
Cout<& lt;" String is empty!" Cout<& lt;" The current order list as follows: ";
for(i=0; iCoutCout}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Void String: : Modify (int place_1, int place_2, char str2 [20])
{
int i;
I=place_2 - place_1;
Str. Replace (place_1, I, str2 [20]);
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Void String: : Insert (int place_3, char str3 [20])
{
Str. Insert (place_3, str3 [20]);
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Void String: : Delete (int place_4, int place_5)
{
int i;
I=place_5 - place_4;
Str. Erase (place_4, I);

}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Void String: : FindString (char str4 [20])
{
Int I, f;
F=Str. Find (str4 [20]);
If (fCout<& lt;" Has been found! Position: "& lt; The else
Cout<& lt;" Not found!" }

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Int the String: : StringLength ()
{
Return Length;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Void Menu ()
{
system("cls");
Cout<& lt;" Order list of basic functions menu "& lt; Cout<& lt;"=========="& lt; Cout<& lt;" 1. Order list (only single-line string, it is suggested that there is no Chinese characters,) "& lt; Cout<& lt;" 2. The display list "& lt; Cout<& lt;" 3. Modify the string "& lt; Cout<& lt;" 4. Insert the string "& lt; Cout<& lt;" 5. Delete the string "& lt; Cout<& lt;" 6. Search string "& lt; Cout<& lt;" 7. String length "& lt; Cout<& lt;" 8. The end of the program "& lt; Cout<& lt;"=========="& lt; }

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
//place_1 place_2 used to modify the
//place_3 for inserting
//place_4 used to delete
//str2 (modified), str3 (insert), str4 (find)
Int main ()
{
Int place_1 place_2, place_3 place_4, place_5;
Str3 char str2 [20], [20], str4 [20].
Int cho.
String String (char STR [20], int length);
While (1)
{
The Menu ();
Do
{cout<& lt;" Please enter a choice: ";
Cin> Cho.
} while (cho<1 | | cho> 8);
The switch (cho)
{
Case 1:
Cout<& lt;" Please enter the need to create a string and ended up with Ctrl + Z!" String. CreateString ();
Cout<& lt;" The character to create success!" break;

Case 2:
String. ShowString ();
break;

Case 3:
Cout<& lt;" Please enter the need to modify the string at the beginning of the position: ";
Cin> Place_1;
CoutCout<& lt;" Please enter the need to modify the string at the end of the position: ";
Cin> Place_2;
Cout<& lt;" Please enter the want to change into a string: ";
Cin> Str2;
String. Modify (place_1 place_2, str2 [20]);
Cout<& lt;" Insert success!" break;

Case 4:
Cout<& lt;" Please enter the location of the insert: ";
Cin> Place_3;
CoutCout<& lt;" Please enter a substring: insert ";
Cin> Str3 [20].
String. The Insert (place_3, str3 [20]);
break;

Case 5:
Cout<& lt;" Please delete the input at the beginning of the position: ";
Cin> Place_4;
CoutCout<& lt;" Please delete the input at the end of the position: ";
Cin> Place_5;
String. The Delete (place_4 place_5);
Cout<& lt;" Deleted successfully!" break;

Case 6:
String. FindString (str4 [20]);
break;

Case 7:
Cout<& lt;" The current length of the string is: "& lt; break;

Case 8:
return 0;

}
system("pause");
Cin. The get ();//extraction of a character from the specified input stream, prevent the screen flashes a
}
}




CodePudding user response:

The String aString (char STR [20], int length);
String is a standard library class, name conflict,

CodePudding user response:

I change the object name is the same error, it may be the real problem is not this!nullnullnullnullnullnullnullnullnullnullnullnull
  • Related