Hey guys, this is my first post. I used to use these forums a long time ago when I fiddled around with C in highschool. Anyways, after a 4 year stint in the Marine Corps, I'm going to college for a degree in engineering and physics at Georgia Tech. I'm starting in August. I've been advised by some contacts that knowledge of a programming language is good to have on a resume if I get into research and development in biomedical engineering, which is my goal. So... I'm working on C++ right now, and I'm getting into the "for" and "while" loops. I'm using a copy of C++ for Dummies that I managed to scrounge up for free, and I'm running the Code::Blocks compiler on Windows 7.
Here is the block of code that I'm working with to make this easy for you to see what I'm referencing. All of the comments are ones that I did on my own to kind of help me talk myself through the code.
Code:
#include <iostream>
#include <cstdio>
#include <cstdlib>
int main(int nNumberofArgs, char* pszArgs[])
{
//input the loop count
int loopcount; // initating the argument named loopcount interger type
std::cout << "Enter loopCount: ";
std::cin >> loopcount; //takes input from user and puts into loopcount
for (int i =1; i <= loopcount; i++)
// it's saying the argument interger type "i" is equal to 1. When it's
// compared to the argument loopcount, run the loop as long as it's less
// than or equal to loopcount. the i++ means to add 1 at the start of the
// loop to the argument "i"
{
std::cout << "We've finished " << i << " loops\n";
}
/* the COUT statement is saying print the text, then print interger "i"
then print loops followed by a newline. then repeat the for loop.
*/
system("PAUSE");
return 0;
}
So my first question is on the #include header part. I think I grasp the concept of what a header is. If I got it right, it's basically a list of definitions for commands I use? So the book isn't explaining to me when to use which one.
1. When I searched online for cstdlib, I got a list of functions and the explanation that it's for memory allocation and lists and sorts. Do I even need this in the program I'm using? The list of functions didn't show anything I use in that block of code.
2. cstdio looks like something for input/output, but online referencing says it's formatted IO functions. Can someone elaborate for an idiot? Once again... I don't see how I need it in this program.
3. ...int main(). I don't understand the (int nNumberofArgs, char* pszArgs[]) part. I searched the string on google, and got limited results. I was thinking maybe something to do with declaring an array or matrix with the [] brackets. Could someone explain this to me in a basic way. No need to go too deep. And once again..... Is this even necessary in this program?
4. And finally.... I took out the books original content to include using namespace std. I read somewhere online that this is inefficient, and so instead I did the other method above in the code. Am I looking at this in the right way, or is there a potential problem with my styling of the code?
The book isn't explaining these things it includes at all. I'm about to go ahead and get a different book by a new author. Until then, could I get some help? By the way remember, I'm a 1 week C++ veteran so don't give me a stroke with technical stuff yet!
Thanks guys!
Semper Fi.