编译程序时,出现一些错误,我找不到错误的解决方案。你能帮助我吗? 错误(带有行号和列号)是:
ERROR1:24 49 [Error] request for member 'substr' in 'month.std::basic_string<_CharT, _Traits, _Alloc>::operator[]<char, std::char_traits<char>, std::allocator<char> >(((std::basic_string<char>::size_type)i))', which is of non-class type 'char'
ERROR2:44 16 [Error] expected ')' before ',' token
44 17 [Error] expected primary-expression before 'int'
ERROR3:47 2 [Error] expected primary-expression before 'catch'
ERROR4:52 2 [Error] expected unqualified-id at end of input
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class Date{
public:
int day;
string month;
int year;
Date(int d,string m,int y):day(d),month(m),year(y) {}// cons. func.
};
class Person{
private:
string first;
string last;
Date birthday; //member object.
public:
Person(string f,string l,int d,string m,int y): first(f),last(l),birthday(d,m,y){} //use member initialize for the member obj.
void setMonth(string month){
string months[12]={"January","February","March","April","May","June","July","August","September","October","November","December"};
string months1[12];
for(int i=0;i<11;i++) {
months[i]=new char ;months[i];
if(months[i].substr(0,3)==month[i].substr(0,3)) //ERROR 1
months[i]=month; //
}
}
void printInfo(ostream){cout<<"Incorrect input for day/year:"<<birthday.day<<birthday.year<<endl;}
int main() {
string first,last,month;
int day,year;
ifstream inp("inputfile.txt");
Person p(first,last,day,month,year);
const char *months[12]={"January","February","March","April","May","June","July","August","September","October","November","December"};
while(!inp.eof()){
try{
inp>>first>>last>>day>>month>>year;
if(year>2020 || day>30) throw year,day;
for(int i=1;i<=12;++i)
if(month!=months[i]) throw month;
ofstream out("outputfile.txt");
}
catch(int year,int day){ //ERROR 2
p.printInfo();
}
catch(string month){ //ERROR 3
out<<"Incorrectly inputted month:"<<month<<"is corrected to"<<p.setMonth()<<endl;
}
return 0;
}} //ERROR 4