C++ 错误C2664字符[80]到字符
嗨,我想创建一个程序来读取一个.txt文件,并将txt中的信息保存到一个struct和enum中(必须使用enum,因为它是强制性的),然后在重新排列单词后打印出信息。例如C++ 错误C2664字符[80]到字符,c++,arrays,enums,char,cstring,C++,Arrays,Enums,Char,Cstring,嗨,我想创建一个程序来读取一个.txt文件,并将txt中的信息保存到一个struct和enum中(必须使用enum,因为它是强制性的),然后在重新排列单词后打印出信息。例如 莎拉 仙境 天秤座2-10-1993 3 我想…… 我希望…… ............ 到 我叫莎拉 我的国籍是仙境 我的生日是1993年10月2日 我是天秤 我有三个愿望 1.我想…… 2.我希望…… 3. ............ 对于getHoroNum和checkHoro,我遇到了类似的错误C2664,指出它无
莎拉
仙境
天秤座2-10-1993
3
我想……
我希望……
............
到
我叫莎拉
我的国籍是仙境
我的生日是1993年10月2日
我是天秤
我有三个愿望
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];
}
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
常数int MAX=80;
常数int MAXNO=10;
黄道带
{
水瓶座,双鱼座,白羊座,金牛座,
双子座,巨蟹座,狮子座,处女座,
天秤座,天蝎座,射手座,摩羯座
};
结构日期
{
黄道十二宫;
国际日;
整月;
国际年;
};
体类型
{
字符名[MAX];
char国籍[MAX];
出生日期;
int no;//其他消息的数目
char-wishMessage[MAXNO][MAX];
};
作废myInfo(流媒体和字符[],学生和);
//上述函数从文本文件中读取信息
//并将信息存储在结构参考参数中
无效打印输出(学生,字符[],字符[]);
void getHoroNum(char,Student&);
无效支票(字符,学生);
void getMth(int,char[]);
int main()
{
河道充填;
字符fName[MAX];
char-horo[MAX];
char fHoro[MAX];
字符mth[MAX];
整月;
学生信息;
cout>fName;
cout>info.birthDate.day
>>临时工
>>info.birthDate.month
>>临时工
>>info.birthDate.year;
infle>>info.no;
对于(int i=0;i 您是否有此函数定义:
void getHoroNum(char horo[], Student& info)
在你得到这份声明之前:
void getHoroNum(char , Student&);
后者应改为:
void getHoroNum(char* , Student&);
您已经将getHoroNum
声明为void getHoroNum(char,
而不是void getHoroNum(char[],
以及已经指出的其他错误,您需要更改所有strcmp
测试,因为逻辑是反向的(strcmp
当字符串完全匹配时返回0)。因此,将:if(strcmp(horo,Aquarius))
更改为:if(strcmp(horo,Aquarius))==0
等等……顺便说一句,您的程序可以编写得更加优雅。非常感谢您的帮助!为错误感到抱歉。非常感谢!我终于可以得到一些输出了,为犯下的愚蠢错误感到抱歉!>。