Starting from scratch. What should I start studying from?

It's about to be my second in college after this summer. None of the classes that I have taken are related to computer science or even just science.
I don't know how this idea came to my head and it makes me want to get into this field.
The last math class that took was pre-calculus in high school.

I just started watching some videos and articles about variables on youtube and google. I understand like 50% in the hello world program but I have no idea why we use things like "iostream" and "#inculde" or why are there parenthesis after int main.

I just want to know, as a beginner that knows nothing about these stuffs, where and what should I start studying from? Is it too early for me to start learning C++language right now? What are some of the things that I need to know before that?

Please give me some suggestions and advises, thank you.
Last edited on
Book wise I'd recommend in this order:

Programming: Principles and Practices Using C++
C++ Primer (not to be confused with C++ Primer Plus)
The C++ Standard Library: A Tutorial and Reference
The C++ Programming Language (as a reference book to the language)


#include tells the preprocessor to include all the contents of iostream into your file. iostream is where cout and cin (among other things) are defined in the namespace std which we use for console output and input, respectively.

int main() has the parentheses because you can specify int argc, char **argv // or *argv[] . This makes is to if you are starting the program from the command line it can be passed parameters (even if it is a program with a GUI). This is a terrible example, but think it helps make it a little clearer:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <string>

int main(int argc, char **argv) 
{	
	std::string usrname, passwrd;
	if (argc >= 3){ // ./filename is always the first element so I have to make sure it is above 
		// 3 in order to do this next part or get a segfault
		usrname = argv[1];
		passwrd = argv[2];
	}else{
		std::cout << "Not enough arguments passed!\n"; // so if I do ./filename or ./filename something I'll get this 
                // would have been better to output usage instead of this silly message
                // std::cout << "Usage: " << argv[0] << " [username] [password]\n";
	}

	if(usrname == "root"){
		if(passwrd == "passkey"){
			std::cout << "Welcome admin!\n";
		}
	}else{
		std::cout << "Sorry, you are logged in as Guest!\n";
	}
	return 0;
}
:~/projects/cpp/tests$ ./testmain
Not enough arguments passed!
You are logged in as Guest!
:~/projects/cpp/tests$ ./testmain root passkey
Welcome admin!
Last edited on
Topic archived. No new replies allowed.