I'm getting this error while initializing a string in a class
Error : publicclass.cpp:13:6: error: array type 'char [50]' is not assignable s.n = "Randomstring";
But char is working. Only getting error with strings
#include<iostream>
using namespace std;
class student
{
public:
int ht;
char n[50];
};
int main()
{
student s;
s.ht = 1;
s.n = "Randomstring";
cout<<"Hallticket no : "<<s.ht<<"\n";
cout<<"Name : "<<s.n<<"\n";
return 0;
}
Compiler version is g++ 8.0.0 (getting same error with clang++ ,turboc++(in windows))
Aucun commentaire:
Enregistrer un commentaire