Can't find the error in the code

Hey Guys

I'm watching a tutorials by Buckys C++ eps. 13.
link (https://www.youtube.com/watch?v=jTS7JTud1qQ)
And in this eps. his writting down a code (Hi is telling us that is the wrong way too use the "Class" and "objeckt". But it occordet a error so must find out wats wrong)
And i can't find i way why this is not working...
So i'm seeking the answere online.
(I'm sorry if I may have bad Englsih)


[output]#include <iostream>
#include <string>
using namespace std;

class ErronsClass
{
public:
string name;
};


int main()
{
ErronsClass Eclass;
Eclass.name = "Hello World!" << endl;
cout << name;
return 0;
}
Last edited on
Please use code tags, it makes the code much easier to read for all of us.

Anyway, your problem is the line where you are assigning "Hello World" to Eclass.name. The '<< endl;' bit doesn't make any sense in terms of a string, it only makes sense when combined with an output stream (like cout). Try this instead:
1
2
3
4
5
6
7
//...
int main() {
    ErronsClass Eclass;
    Eclass.name = "Hello World!";
    cout << Eclass.name << endl;
    return 0;
}
Thx NT3! It did work, and now I can learing on in peace...
And by the way, how do I use code tags?
Last edited on
If you look at the side bar, there is a thing with 'Format:', and a whole bunch of little buttons underneath it. Select your code and click the one that shows a '<>' symbol. Alternately, you can do the same thing by writing:
[code]Your code goes here[/code]
Last edited on
Topic archived. No new replies allowed.