我刚刚开始使用类,在这段代码中,我试图让一个类从用户那里获取一个字符串,计算它的长度然后打印它。但是我遇到了一些错误,我无法理解它们的用途。我会很感激一些帮助。
#include<iostream>
using namespace std;
class String
{
public:
    String();  // constructor
    void Print();   // printing the string
    void Get();     // getting the string from the user.
    int CountLng( char *);   // counting length
    ~String();  // destructor
private:
    char *str;
    int lng;
} str1;
String::String()
{
    lng=0;
    str=NULL;
}
int CountLng( char *str)
{
    char * temp;
    temp=str;
    int size=0;
    while( temp !=NULL)
    {
        size++;
        temp++;
    }
    return size;
};
void String::Get()
{
    str= new char [50];
    cout<<"Enter a string: "<<endl;
    cin>>str;
};
void String::Print()
{
    cout<<"Your string is : "<<str<<endl<<endl;
    lng= CountLng( str);
    cout<<"The length of your string is : "<<lng<<endl<<endl;
};
int main()
{
    str1.Get();
    str1.Print();
    system("pause");
    return 0;
}