Saturday, May 22, 2010

What are these C++ terms?? Shown below. Pls be conservative as I am big dummy.?

# include %26lt;iostream%26gt;??


using namespace std??


arrays??

What are these C++ terms?? Shown below. Pls be conservative as I am big dummy.?
go to this link it should help:





http://pages.cs.wisc.edu/~hasti/cs368/Cp...
Reply:#include %26lt;iostream%26gt; // Defines global object std::cout


It includes the header file contains some input output functons.








using namespace std; // Allow std:: to be dropped





An array is a data structure which allows a collective name to be given to a group of elements which all have the same type
Reply:Speaking as a C programmer who never fully made the transition to C++,





Your compiler path usually includes at least 3 directories. Most of the compilers I've worked with (which in recent years have been GCC, GCC and, you guessed it GCC) keep at least the compiler and linker plus other files in the bin directory, header files in the include directory, and library files in the lib directory. Library files are files which contain the object code which run the various standard functions like printf() or malloc in C and cout or new in C++. The compiler will not understand them though, though the files are usually linked in anyhow, unless you include or #include (notice I put no space between the pound sign and the word) the relevant header file.





Iostream, formerly iostream.h, is the file which declares input and output functions such as cout, cin and the %26lt;%26lt; and %26gt;%26gt; operators. By enclosing it in the %26lt; and %26gt; signs, you are telling the compiler (or more properly the preprocessor) to look in the include directory for the file named iostream. If you wanted the compiler to look in the current directory, because you had created your own header file for example, you would do #include "myfile.h" or #include "myfile" depending on what you had named it.





Before going further, I recommend to anyone who wants to learn C or C++ going to their include directory and reading the header files. They are text files, the lib files are not. You will get to see how many functions are defined and learn a lot about how your compiler works. DO NOT edit them. In fact DOS and Linux console's more commands, which display the contents of these files without allowing edit, are preferable to opening them up in any editor.





While namespaces are a topic which has been a part of C++ for quite a while up until the introduction of the Standard Template Library (STL) which was when iostream.h and other include files lost their h's the functions and operators they declared were global variables, accessible by default from any namespace. For reasons I won't pretend to understand, so can't explain, with this change they were assigned to the namespace std. Notice the line is using namespace std; . It ends in a semi-colon. DO NOT omit it from that line or put it after an #include %26lt;anyheaderfile%26gt; line. If you omit that line, or get it wrong and it wants to compile, the program will be unable to access any important function or operator unless you preface it with std:: as in std::cout... For now I would do it because you are told to. As you gain experience with C++ you will find yourself looking at namespaces and should be able to figure out why this is.





Arrays are collections of objects. More accurately, they are blocks of memory set aside to store objects. By objects I mean anything. Ints, chars floats, doubles or structs classes or enums or user defined objects such as family members or kitchen sinks. I want to start talking about Dynamic variables, The subjects of arrays and Dynamic variables are very intimately related. Nevertheless it is an advanced topic. Let's just say that for an array of int Joe[30] the variables Joe and the address of Joe[0] are exactly the same and you can print the contents of Joe[0] by doing a cout %26lt;%26lt; *Joe at least on my compiler. And that is one reason arrays start with 0 rather than 1 (so the last element of Joe would be Joe[29] which with Joe[0] gives 30 elements. Joe[1] is *Joe+1 etc.





At this point if I'm going too fast and too far, sorry.
Reply:1. Include the input/output stream library (just a bunch of basic pre-defined functions)





2. Include the "standard" namespace so that you won't have to type "std" every other second (std::cout to just cout)





3. Just a table of variable defined by how many rows and columns it has.





I hope that was clear and simple!


No comments:

Post a Comment