It does, and no, I didn't forget.It shouldn't. You forgot to #include <cstdio>.
It does, and no, I didn't forget.It shouldn't. You forgot to #include <cstdio>.
Last edited by 7stud; 05-31-2003 at 08:21 PM.
getchar( ) is defined in <cstdio>, not <iostream>.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
Ok, i think i did this right, but it won't compile. Ill post the code and the compiler errors.
Code:#include <iostream> #include <stdlib.h> #include <fstream.h> class workingclass { public: workingclass(); ~workingclass(); }; workingclass() { cout<<"stuff"; } ~workingclass() { } int main(int argc, char *argv[]) { system("PAUSE"); return 0; }
And the errors i get....
Code:12 C:\Documents and Settings\User\Desktop\main.cpp parse error before `(' 17 C:\Documents and Settings\User\Desktop\main.cpp destructors must be member functions C:\Documents and Settings\User\Desktop\Makefile.win [Build Error] [main.o] Error 1
~matt~
Almost there.
1)Don't use header files with .h extensions. Use the equivalent header names found here:
http://www.cplusplus.com/doc/ansi/hfiles.html
2)Add a using declaration after your includes, like
using namespace std;
3)For short functions you should just define them inside the class. If you do define a function outside the class, it must be qualified with the class name, so that the compiler knows what class the definition belongs to, like this:
Just add "workingclass::" in front of any function you define outside of your class. Also, if you had a function with a return type of int, this is what the format would look if you defined it outside the class:Code:workingclass::workingclass() { cout<<"stuff"; }
The return type goes all the way to the left.Code:int workingclass::my_function() { ..... return 50; }
4)Unless you're going to be using arguments entered on the command line(which I assume you aren't) use the following format for main():
It's much easier to type.Code:int main() { .... .... return 0; }
Last edited by 7stud; 06-01-2003 at 04:07 AM.
You have to? Who says so? You are already using one non-h header (<iostream>), so you can use all others too.I have to use .h, thats why i do that. Someone esle already told me that above.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
When i delete off the .h, i get compiler errors. Does it really make a difference anyways?
Also, what excactly does "using namespace std;" or whatever it was, do?
~matt~
Ok, update, scratch that compiler error stuff with the .h. I didnt know that it was written different in C++.
~matt~