c ++

时间:2017-03-26 15:18:53

标签: c++

我在ob1.name和ob2.name上遇到左值必需错误。请
        帮我解决一下。

 #include<iostream.h>
 #include<conio.h>
 class student
 {
 public:
   int rollno;
   char name[10];
 };

 void main()
 {
   student ob1;
   student ob2;
   ob1.rollno=101;
   ob1.name="ajay"; // this is where i am getting the error
   ob2.rollno=102;
   ob2.name="pintu"; // this is where i am getting the error
   clrscr();
   cout<<"roll no and name of first student"<<ob1.rollno<<ob1.name;
   cout<<"roll no and name of second student"<<ob2.rollno<<ob2.name;
   getch();
 }

1 个答案:

答案 0 :(得分:0)

您需要使用strcpy

strcpy(ob1.name, "ajay");

但更好的解决方案是使用std::string

相关问题