| | |
.h source file acting up
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 1
Reputation:
Solved Threads: 0
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:
Box.cpp:
boxDriver.cpp:
Thanks
box.h:
C++ Syntax (Toggle Plain Text)
#ifndef _BOX #define _BOX #include <string> #include <iostream> using namespace std; class Box { private: double height, width, depth; string name; public: Box(); Box(double,double,double,string); void setHeight(double); void setWidth(double); void setDepth(double); void setName(string); double getHeight(); double getWidth(); double getDepth(); double Area(); double Volume(); void Display(ostream&); }; #endif
C++ Syntax (Toggle Plain Text)
#include "Box.h" #include <string> #include <iostream> using namespace std; Box::Box() { height = 0; width = 0; depth = 0; } Box::Box(double h,double w,double d) { height = h; width = w; depth = d; } void Box::setHeight(double h) { height = h; } void Box::setWidth(double w) { width = w; } void Box::setDepth(double d) { depth = d; } void Box::setName(string n) { name = n; } double Box::getHeight() { return height; } double Box::getWidth() { return width; } double Box::getDepth() { return depth; } std::string Box::getName() { return name; } double Box::Area() { return 2 * (height * width) + 2 * (width * depth) + 2 * (height * depth); } double Box::Volume() { return height * width * depth; } void Box::Display(ostream &output) { output << "Height = " << height << std::endl << "Width = " << width << std::endl << "Depth = " << depth << std::endl << "Name = " << name; }
C++ Syntax (Toggle Plain Text)
#include "Box.h" #include <iostream> #include <string> using namespace std; int main() { cout << "\n\n OUTPUT FROM SAMPLE DRIVER\n\n\n"; Box a(5, 2.3, 10.1); a.setName("Box 1"); cout << "CALL DISPLAY FUNCTION \n"; a.Display(cout); cout << endl; cout << "\n*** END Display Function *** \n\n"; cout << "Area = " << a.Area() << endl; cout << "Volume = " << a.Volume() << endl; cout << "\n\n******************* Second Box ***********************\n\n\n"; Box b; // Set Attributes b.setHeight(2.7); b.setWidth(24.05); b.setDepth(3.22); b.setName("Box 2"); cout << "CALL DISPLAY FUNCTION \n"; b.Display(cout); cout << endl; cout << "\n*** END Display Function *** \n\n"; cout << "Area = " << b.Area() << endl; cout << "Volume = " << b.Volume() << endl;; cin.get(); return 0; }
Last edited by Ancient Dragon; Nov 19th, 2008 at 5:38 pm. Reason: add code tags
>>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.
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.
![]() |
Similar Threads
- Strange Computer Problems (Viruses, Spyware and other Nasties)
- weird startup virus? please help!! (Viruses, Spyware and other Nasties)
- Square Image Thumbnail (PHP)
- option dropdown can't see options (PHP)
- I NEED HELP WITH "Generic Host Process for Win32 Services ERROR" (Viruses, Spyware and other Nasties)
- problem in javascript coding in asp page (ASP)
- Hijackthis log RE: Trojan.Abwiz.F virus (Viruses, Spyware and other Nasties)
- Edit flash? (Graphics and Multimedia)
- HOTOFFER.INFO Malware removal (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Inheritence, .h files and its a long one
- Next Thread: Array Algorithm
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg simple sorting string strings template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






