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;
};

Recommended Answers

All 2 Replies

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.