having a problem with strings in class

getting errors i don't understand dealing with my strings

Page 1 of 1

4 Replies - 465 Views - Last Post: 06 March 2010 - 12:53 AM Rate Topic: -----

#1 Guest_woodpryan*


Reputation:

having a problem with strings in class

Posted 05 March 2010 - 08:42 PM

The object of this program is to build a class with inherited values from another. i am having a problem with a strange error that i don't quite understand with this code. this is the .h file of the program.
#ifndef EX_CLOCK_TYPE_H
#define EX_CLOCK_TYPE_H

#include <iostream>
#include <string>

#include "clockType.h"

class exClockType: public clockType
{
private: string zone;

public:
	void setTime(int, int, int, string zone);
	//function to set the time and time zone
	//postcondition: hr = hour; min = minutes; sec = seconds;
	//function checks to insure that the values of hours, minutes,
	//and second are valid
	//default value 0 is assigned to min, sec, hr.
	//the default value "" is assigned for timeZone

	void printTime() const;
	//function to print the time and time zone.
	//postcondition: the time is printed in the form
	//hh:mm::ss
	//the Time Zone is also printed.

	void setTimeZone(string zone);
	//function to set the time zone
	//postcondition: the time zone is set according to the
	//parameters.
	//zone = timeZone;

	exClockType();
	//default constructor
	//postcondition: zone = ""
	//               hr = 0; min = 0; sec = 0;
	
	exClockType(int, int, int, string zone);
	//constructor with parameters
	//postcondition: hr = hours; min = minutes; sec = seconds;
};

#endif



i am compiling this in g++ and these are the errors i'm recieving:

Quote

frankenbox Programming # g++ exClockType.h
exClockType.h:11: error: 'string' does not name a type
exClockType.h:14: error: 'string' has not been declared
exClockType.h:28: error: 'string' has not been declared
exClockType.h:39: error: 'string' has not been declared

i've been trying to figure this out for an hour. it's probably an obvious error and i'm going to kick myself when some one points it out, but i can't find it. can anyone help?

Is This A Good Question/Topic? 0

Replies To: having a problem with strings in class

#2 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: having a problem with strings in class

Posted 05 March 2010 - 08:44 PM

You forgot "using namespace std;".
Was This Post Helpful? 0
  • +
  • -

#3 Guest_woodpryan*


Reputation:

Re: having a problem with strings in class

Posted 06 March 2010 - 12:46 AM

holy crap!
thank you man. i don't know why i forgot that or why i couldn't find it. i just figured i needed to step back from it and let someone else take a look at it. thanks a lot. what a stupid error.
Was This Post Helpful? 0

#4 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: having a problem with strings in class

Posted 06 March 2010 - 12:50 AM

This is partially why I advocate always using std::string, std::cout etc. instead of using namespace std;.
Was This Post Helpful? 1
  • +
  • -

#5 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: having a problem with strings in class

Posted 06 March 2010 - 12:53 AM

I always avoid the "using namespace _X" is a header file. There's really no need for it. How lazy can you be to not write std:: prefix in 3 or 4 places?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1