.h source file acting up

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2008
Posts: 1
Reputation: hello11 is an unknown quantity at this point 
Solved Threads: 0
hello11 hello11 is offline Offline
Newbie Poster

.h source file acting up

 
0
  #1
Nov 17th, 2008
Here is my code I'm pretty sure the problem has to do with using namespace std and the included header files but I can't figure it out (error string no such file or directory in .h, error iostream no such file or directory in .h,error syntax error before namespace)

box.h:
  1. #ifndef _BOX
  2. #define _BOX
  3.  
  4. #include <string>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. class Box
  11. {
  12. private:
  13. double height, width, depth;
  14. string name;
  15. public:
  16. Box();
  17. Box(double,double,double,string);
  18. void setHeight(double);
  19. void setWidth(double);
  20. void setDepth(double);
  21. void setName(string);
  22. double getHeight();
  23. double getWidth();
  24. double getDepth();
  25. double Area();
  26. double Volume();
  27. void Display(ostream&);
  28. };
  29.  
  30. #endif
Box.cpp:
  1. #include "Box.h"
  2. #include <string>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. Box::Box()
  8. {
  9. height = 0;
  10. width = 0;
  11. depth = 0;
  12. }
  13. Box::Box(double h,double w,double d)
  14. {
  15. height = h;
  16. width = w;
  17. depth = d;
  18. }
  19. void Box::setHeight(double h)
  20. {
  21. height = h;
  22. }
  23. void Box::setWidth(double w)
  24. {
  25. width = w;
  26. }
  27. void Box::setDepth(double d)
  28. {
  29. depth = d;
  30. }
  31. void Box::setName(string n)
  32. {
  33. name = n;
  34. }
  35. double Box::getHeight()
  36. {
  37. return height;
  38. }
  39. double Box::getWidth()
  40. {
  41. return width;
  42. }
  43. double Box::getDepth()
  44. {
  45. return depth;
  46. }
  47. std::string Box::getName()
  48. {
  49. return name;
  50. }
  51. double Box::Area()
  52. {
  53. return 2 * (height * width) + 2 * (width * depth) + 2 * (height * depth);
  54. }
  55. double Box::Volume()
  56. {
  57. return height * width * depth;
  58. }
  59. void Box::Display(ostream &output)
  60. {
  61. output << "Height = " << height << std::endl
  62. << "Width = " << width << std::endl
  63. << "Depth = " << depth << std::endl
  64. << "Name = " << name;
  65. }
boxDriver.cpp:
  1. #include "Box.h"
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. cout << "\n\n OUTPUT FROM SAMPLE DRIVER\n\n\n";
  10.  
  11. Box a(5, 2.3, 10.1);
  12. a.setName("Box 1");
  13.  
  14.  
  15. cout << "CALL DISPLAY FUNCTION \n";
  16. a.Display(cout);
  17. cout << endl;
  18. cout << "\n*** END Display Function *** \n\n";
  19.  
  20.  
  21. cout << "Area = " << a.Area() << endl;
  22. cout << "Volume = " << a.Volume() << endl;
  23.  
  24. cout << "\n\n******************* Second Box ***********************\n\n\n";
  25. Box b;
  26.  
  27. // Set Attributes
  28.  
  29. b.setHeight(2.7);
  30. b.setWidth(24.05);
  31. b.setDepth(3.22);
  32. b.setName("Box 2");
  33.  
  34. cout << "CALL DISPLAY FUNCTION \n";
  35. b.Display(cout);
  36. cout << endl;
  37. cout << "\n*** END Display Function *** \n\n";
  38.  
  39.  
  40. cout << "Area = " << b.Area() << endl;
  41. cout << "Volume = " << b.Volume() << endl;;
  42.  
  43. cin.get();
  44. return 0;
  45. }
Thanks
Last edited by Ancient Dragon; Nov 19th, 2008 at 5:38 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,521
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1480
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: .h source file acting up

 
0
  #2
Nov 19th, 2008
>>error string no such file or directory in .h
What compiler are you using? That error would indicate you are usiing something readlly really old, like ancient Turbo C what knows nothing about <string> header file.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC