gpt4 book ai didi

c++ - 错误 C2664 char [80] 到 char

转载 作者:行者123 更新时间:2023-11-28 02:51:36 27 4
gpt4 key购买 nike

<分区>

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


我叫莎拉
我的国籍是仙境
我的生日是 1993 年 10 月 2 日
我是天秤座

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

对于 getHoroNum 和 checkHoro,我遇到了类似的错误 C2664,指出它无法将参数 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];
}
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com