+ 1
can anyone help m out plz
i wrote this program to show student name and student id #include <iostream> #include <string> using namespace std; class myClass { public: string name; int id; }; int main() { myClass myObj; myObj.name = "SoloLearn"; myobj.id= 12345; cout << myObj.name<<"\t"<<myobj.id; return 0; } what is wrong????
6 odpowiedzi
+ 1
Your variable name is off.
Cout statement you are using myobj.id, should be myObj.
+ 1
hey guys i got the answer
this is the correct program
#include <iostream>
#include <string>
using namespace std;
class myClass {
public:
string name;
int id;
};
int main() {
myClass myObj;
myObj.name = "SoloLearn";
myObj.id= 167;
cout <<" the name of the student is:::"<< myObj.name<<"\n\n\n\n\n the id of the student is :::"<<myObj.id;
return 0;
}
0
compiler shows me errer
output
0
And as well as your assignment
0
Sorry I didn't not get you
0
Good that you found an answer that suits you, but that doesn't mean it's the right answer. C++ has a mechanism for handling formating the output which is why your code failed in the first place.
http://www.cprogramming.com/tutorial/iomanip.html