The below given program shows the following error: incompatible types in assignment of 'const char [12]' to 'char [25]'What does this error mean ?
Why is it coming
#include <iostream>
#include <string>usingnamespace std;
struct date
{
int day;
int month;
int year;
};
struct student
{
string name;longint rollno;
date dob;
};
int main()
{
student a;
a.name = "Shivam Jain";
a.rollno = 16530020;
a.dob.day = 1;
a.dob.month = 6;
a.dob.year = 1994;
cout << a.name << endl;
student b = {"Shivam Jain", 16530020, 1, 6, 1994 };
cout << b.name << endl;
}
Or stay with the use of character arrays. Then you need the slightly different header #include <cstring> and you need the functions strcpy(), strcmp(), strcat() and so on.
In the widesweep of things, avoiding problems with leading zeroes, searches etc it is not always a good idea to use integers. <string>'s or even c-style strings enable greater functionality in the long run.