0

How does one declare a string as a data member in a class? I tried it this way, but my compiler says that's not it

class cdrom
{
	public:
			cdrom();
			void loadinfo();
			float returncost();
			void displayinfo();
			void changedata ();

	private:
			float cost;
			string name;
			string cdtype;
};
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by henpecked1
0

Perhaps post error messages?

Perhaps #include <string> Perhaps say std::string cdtype; One thing you must NOT do however is be tempted to putting using namespace std; inside your header files, because you're too lazy to type std:: a few times.
Anyone including your file would then get the whole std namespace thing whether they wanted it or not. And if they didn't want it, then there would be no way out for them but to send you a bug report to fix your header file.

0

Nm, I got it. Thank you anyway. Oh, and thanks for the namespace tip, I learned that the hard way already...lol. Now I use it while I"m building, but then go back and replace it with the appropriate std:: lines

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.