注册 登录
编程论坛 VC++/MFC

急需解疑!谢谢!!

yang20110816 发布于 2011-05-23 01:27, 296 次点击
#include <iostream>
#include <string.h>
using namespace std;
 
class Mystring{
public:
    Mystring(char str1[90]="string",char str2[90]="number"){
        a=str1;
        b=str2;
    }
    ~Mystring(){
        cout<<"Destructor called"<<endl;
    }
    string setstring(char str1[90],char str2[90]){
        a=str1;
        b=str2;
        cout<<"input the string 1:"<<endl;
        cin>>str1;
        cout<<"input the string2 :"<<endl;
        cin>>str2;
        return a;
            return b;

    }
    string showstring(char str1[90],char str2[90]){

        gets(a);
        gets(b);
        if(strcmp(a,b)!=0)
            if(strcmp(a,b)>0)
                cout<<"the string 1 is greater than string 2:"<<a<<endl;
            else
                cout<<"the string 1 is less than string 2:"<<b<<endl;
            else
                cout<<"the string 1 is equal to string 2:"<<a<<endl;
            return a;
            return b;
            
    }

private:
    //char *str1,*str2;
    char *a,*b;


};

string Mystring::setstring(char str1[90],char str2[90]);
string Mystring::showstring(char str1[90],char str2[90]);

void main(){
    char *a,*b;
    Mystring string();
        string.setstring() ;   
        string.showstring() ;
       string.~Mystring();
}


--------------------Configuration: wefwff - Win32 Debug--------------------
Compiling...
fw.cpp
C:\Program Files\VC++\MyProjects\wefwff\fw.cpp(54) : error C2228: left of '.setstring' must have class/struct/union type
C:\Program Files\VC++\MyProjects\wefwff\fw.cpp(55) : error C2228: left of '.showstring' must have class/struct/union type
执行 cl.exe 时出错.

fw.obj - 1 error(s), 0 warning(s)
4 回复
#2
yang201108162011-05-23 01:28
我要写一个类,然后输入两个字符串,最后比较这两个字符串的大小!!
#3
zhoufeng19882011-05-24 16:54
代码乱得很。代码风格也非常的不好。
你的基础太差了。应该好好学学基础知识。
至少我觉得你应该把C/C++语言的函数、指针学好点。
#4
yang201108162011-05-26 01:53
回复 3楼 zhoufeng1988
我是新手,刚学c++才两三个月,请问有什么好的建议吗?最近正在学数组跟指针,这里有时候有点混,请赐教!!
#5
zhoufeng19882011-05-31 09:21
看<<C++ Primer>>
1