So I'm trying to teach myself C++, but I've stumbled across a programming exercise that I can't figure out. The general idea is this: create a class called Dog which has a string field for the dog's name. In main(), create a dog and assign a name to it. The problem is, it doesn't seem to work the same way as assigning a string in a normal fashion. The way I've been going about it is:
// this is the class
class Dog
{
public:
char dogName[5];
};
// then skipping down to the main () section where I assign a name
Dog oneDog;
oneDog.dogName = {"Spot"};
Which produces errors indicating that the { } should not be there. When I remove the braces:
Dog oneDog;
oneDog.dogName = "Spot";
It gives me the error that "left operand must be l-value." How can I assign a string value to this? I'm also a little confused as to how you would pass an object's value to a function as well. The book I bought has a bad habit of going over how you would do something in an ideal situation but not if it's anything more complicated. Would it be the same as a regular variable like this:
function_name(oneDog.dogName)
Thanks in advance.