I am learning classes now, and for some reason, when I call a class, it is not recognizing my string.
If I put both my new class in main.cpp (in code::blocks), then it works, but when I put the class(called monster) into monster.h, it tells me that 'string' has not been declared(error on line 14 of monster.h). What am I doing wrong?
C++ has "namespaces" which house identifiers (like "string" or "cout", or anything else that you get from including a normal header). The reason it does this is to prevent name conflicts. For example if you write a function named 'swap' it might be a conflict because there already is a function named swap.
So to avoid that conflict, you have to specify which swap you want to use. You do this by specifying which namespace it's in. swap, string, etc are all in a namespace called "std". So their full name is "std::string" and "std::swap".
Now... when you put usingnamespace std; you are taking everything in the std namespace and dumping it into the global namespace. This has the advantage of reducing the typing you have to do, because now you can use the shorter string instead of the full std::string. However it has a disadvantage because it basically completely removes the namespace, opening up possibilities for conflicts.