错误C2664 char [80]到char

时间:2014-04-07 15:34:30

标签: c++ arrays enums char cstring

您好我想创建一个程序来读取.txt文件并将txt中的信息保存到结构和枚举(必须使用枚举。因为它是必须的)然后在重新排列单词后打印出信息。例如
萨拉
仙境
天秤座2 - 10 - 1993
3
我想...... 我希望...
............


我的名字是sarah
我的国籍是仙境 我的bday是1993年10月2日 我是天秤座
我有3个愿望 我想...... 我希望...
3. ............

我遇到类似的错误C2664 for getHoroNum和checkHoro声明它无法转换参数1来自' char [80]'到了' char'。请帮忙!非常感谢提前!

    #include <iomanip>
    #include <iostream>
    #include <cstdlib>
    #include <ctime>
    #include <cctype>
    #include <fstream>
    #include <string>

    using namespace std;

    const int MAX = 80;
    const int MAXNO = 10;

    enum Zodiac 
    {
        Aquarius, Pisces, Aries, Taurus,
        Gemini, Cancer, Leo, Virgo,
        Libra, Scorpio, Sagittarius, Capricorn
    };
    struct Date
    {
        Zodiac sign;
        int day;
        int month;
        int year;
    };
    struct Student
    {
        char name [MAX];
        char nationality [MAX];
        Date birthDate;
        int no; // no of other messages
        char wishMessage [MAXNO][MAX];

    };

    void myInfo (fstream&, char [], Student&);
    // The above function reads information from the text file
    // and store the information in a structure reference parameter

    void printOut(Student , char[], char[]);
    void getHoroNum(char , Student&);
    void checkHoro (char , Student);
    void getMth (int, char []) ;

    int main()
    {
        fstream infile;
        char fName[MAX];
        char horo [MAX];
        char fHoro[MAX];
        char mth[MAX];
        int month;
        Student info;
        cout << "Enter your info file name: ";
        cin  >> fName; 
        cout << endl;

        month = info.birthDate.month;

        myInfo(infile, fName, info);
        getHoroNum(horo, info);
        checkHoro(fHoro, info);
        getMth(month, mth);

        printOut(info, );

    }

    void myInfo (fstream& infile, char fName[], Student& info)
    {
        infile.open(fName, ios::in);
        char temp[MAX];
        char horo[MAX];

        if(!infile)
        {
            cout << "Error file not found!" << endl;
            exit(0);
        }
        infile.getline(info.name, MAX);
        infile.getline(info.nationality,MAX);
        infile  >> horo
            >> info.birthDate.day
            >> temp
            >> info.birthDate.month
            >> temp
            >> info.birthDate.year;
            infile  >> info.no;
        for(int i=0; i < info.no ;i++)
        {
            infile.getline(info.wishMessage[i], MAX);
        }
        infile.close();
        cout << "Successfully readed!" << endl;

    }

    void getHoroNum(char horo[], Student& info)
    {
        if (strcmp (horo,"Aquarius"))
        {
            info.birthDate.sign = Aquarius;
        }
        else if (strcmp(horo,"Pisces"))
        {
            info.birthDate.sign = Pisces;
        }
        else if (strcmp(horo,"Aries"))
        {
            info.birthDate.sign = Aries;
        }
        else if (strcmp(horo,"Taurus"))
        {
            info.birthDate.sign = Taurus;
        }
        else if (strcmp(horo,"Gemini"))
        {
            info.birthDate.sign = Gemini;
        }
        else if (strcmp(horo,"Cancer"))
        {
            info.birthDate.sign = Cancer;
        }
        else if (strcmp(horo,"Leo"))
        {
            info.birthDate.sign = Leo;
        }
        else if (strcmp(horo,"Virgo"))
        {
            info.birthDate.sign = Virgo;
        }
        else if (strcmp(horo,"Libra"))
        {
            info.birthDate.sign = Libra;
        }
        else if (strcmp(horo,"Scorpio"))
        {
            info.birthDate.sign = Scorpio;
        }
        else if (strcmp(horo,"Sagittarius"))
        {
            info.birthDate.sign = Sagittarius;
        }
        else if (strcmp(horo,"Capricorn"))
        {
            info.birthDate.sign = Capricorn;
        }
    }

    void checkHoro (char fHoro[], Student info)
    {
        if (info.birthDate.sign == Aquarius)
        {
            fHoro = "Aquarius";
        }
        else if (info.birthDate.sign == Pisces)
        {
            fHoro = "Pisces";
        }
        else if (info.birthDate.sign == Aries)
        {
            fHoro = "Aries";
        }
        else if (info.birthDate.sign == Taurus)
        {
            fHoro = "Taurus";
        }
        else if (info.birthDate.sign == Gemini)
        {
            fHoro = "Gemini";
        }
        else if (info.birthDate.sign == Cancer)
        {
            fHoro = "Cancer";
        }
        else if (info.birthDate.sign == Leo)
        {
            fHoro = "Leo";
        }
        else if (info.birthDate.sign == Virgo)
        {
            fHoro = "Virgo";
        }
        else if (info.birthDate.sign == Libra)
        {
            fHoro = "Libra";
        }
        else if (info.birthDate.sign == Scorpio)
        {
            fHoro = "Scorpio";
        }
        else if (info.birthDate.sign == Sagittarius)
        {
            fHoro = "Sagittarius";
        }
        else if (info.birthDate.sign == Capricorn)
        {
            fHoro = "Capricorn";
        }
    }

    void getMth (int month, char mth[] )
    {
        switch (month)
        {
            case 1:
        {
            mth = "January";
            break;
        }

            case 2:
        {
            mth = "February";
            break;
        }
            case 3:
        {
            mth = "March";
            break;
        }
            case 4:
        {
            mth = "April";
            break;
        }
            case 5:
        {
            mth = "May";
            break;
        }
            case 6:
        {
            mth = "June";
            break;
        }
            case 7:
        {
            mth = "July";
            break;
        }
            case 8:
        {
            mth = "August";
            break;
        }

            case 9:
        {
            mth = "September";
            break;
        }
            case 10:
        {
            mth = "October";
            break;
        }
            case 11:
        {
            mth = "November";
            break;
        }
            case 12:
        {
            mth = "December";
            break;
        }

        }
    }

    void printOut(Student info, char mth[], char fHoro[])
    {
        cout << "My name is " << info.name << endl;
        cout << "My nationality is " << info.nationality << endl;
        cout << "My date of birth is " << info.birthDate.day 
             << " " << mth << " " 
             << info.birthDate.year << endl;
        cout << "I am a" << fHoro << endl;
        cout << "\nI have " << info.no << " wishes:" << endl;
        for(int i=0; i < info.no ;i++)
        {
            cout << i << ". " << info.wishMessage[i];
        }
    }

1 个答案:

答案 0 :(得分:2)

您有此功能定义:

void getHoroNum(char horo[], Student& info)

在你有这个声明之前:

void getHoroNum(char , Student&);

后者应替换为:

void getHoroNum(char* , Student&);