Sunday, July 12, 2009

What is the standard format for beginning C++ code (pre-code text)?

I've found multiple suggestions, and am curious about the "best" or most widely used. I'm a novice C++ programmer, and am wondering what the most common basic beginning of a C++ source is.

What is the standard format for beginning C++ code (pre-code text)?
For most of the applications that you will be writing in an introduction course, your source will be laid out as follows:





// helloworld.cpp


// 27 June 2007


// Print "Hello World!" to the console.





// Include necessary headers


#include %26lt;iostream%26gt;





// Use the standard name space


using namespace std;





// Main entry point


int main() {


cout %26lt;%26lt; "Hello World!\n";


return 0;


}
Reply:/*The following is pretty standard: Dont forget to comment */





# include %26lt;time.h%26gt; //Header files





main ()


{


application code goes here





}
Reply:#include %26lt;headerfile(s)%26gt;





#define %26lt;global constant(s)%26gt;





%26lt;global function(s)%26gt;





int main()


{


%26lt;main program%26gt;


}
Reply:You need to clarify what you mean. Are you referring to the comments often seen at the beginning of a source file? Or do you mean actual code? Sorry, but I can't do mind reading, so you will have to add in additional details or repost your question, spelling out exactly what you mean.





I suggest you take a look at popular C and C++ libraries. SGI's STLPort, some of the more well-known libraries on Sourceforge, and so on, are good starting points. Exploring the Linux kernel code will allow you to see how they structure their source files as well.





And for the record, there is no standard format.


No comments:

Post a Comment