2014-04-07 33 views
0

嗨我想创建一个程序来读取.txt文件,并将信息保存在TXT结构和枚举(必须使用枚举。因为它强制),然后打印出来重新排列单词后的信息。例如
萨拉
仙境
天秤座2 - 10 - 1993年
我想......
我希望能......
............
错误C2664字符[80]到字符

TO

我的名字是萨拉
我的国籍是仙境
我BDAY是1993年10月2日
我是天秤座

我有3个愿望
1.我想...
2.我希望能......
3. ............

我遇到了类似的错误C2664 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]; 
     } 
    } 
+2

你已经声明'getHoroNum'为'void getHoroNum(char,'而不是'voi d getHoroNum(char [],' –

+2

除了已经指出的其他错误,您需要更改所有'strcmp'测试,因为逻辑反转(当字符串完全匹配时'strcmp'返回0) 。所以改变: '如果(STRCMP(霍拉, “水瓶座”))' 到: '如果(STRCMP(霍拉, “水瓶座”)== 0)' 等等... –

+1

BTW程序可以写得更优雅。 –

回答

2

你有这样的功能定义:

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

,你有此声明之前:

void getHoroNum(char , Student&); 

后者应改为:

void getHoroNum(char* , Student&); 
+0

非常感谢!我终于可以得到一些输出,对于犯下的愚蠢错误感到抱歉! >< –