Some questions(need to know Java)

Hi,so let me introduce my prior knowledge before I get into my questions.
I "know" Java, know isn't a term I would use if you asked me if I know java in real life by any means. I can read Java, not really write any code. If you gave me a .java file and some time I could probably tell you what it does.

So the code I am learning about on the guide here is below.
Here are a few of my questions:
1.Is #include pretty much the same as import in java?
2.Do you ever add anything to int? In java you would see public static blah blah blah, is int like that?
3.Why the :: between std and cout? Is there ever more then one :: in a line?

I'm trying to find ways to explain this to myself in ways similar to what I understand, probably seems annoying sorry.

1
2
3
4
5
6
7
 // my first program in C++
#include <iostream>

int main()
{
  std::cout << "Hello World!";
}


Thanks for your help,
-Tanner
Ive never really programmed java but I'll try to answer the questions.

1. Yes.
2. You can add things to int. Things like "signed" and "unsigned" But just having int is the most normal one (as far as I know)

3. The :: is called the scope-resolution operator and does just that. It ensures that resolution occurs from the global namespace.

For example. "std" the standard c++ library. if you want to use a function that is in the library like cout(output) or cin(input) - (note you also need <iostream> for those) You do std::cout or std::cin. Or, alternatively, although not very liked on the internet for a good reason I'd say, you could do this at the top of your programs

using namespace std;

That will tell c++ that you will be using the namespace std so you can just type cout and cin without the std::

Hope this helped :)
Thank you, that helped, I think, still sort of trying to understand some of it.
I would DEFINITELY recommend watching this guys tutorials - https://www.youtube.com/watch?v=tvC1WCdV1XU&list=PLAE85DE8440AA6B83&ab_channel=thenewboston

You'll know the basics inside and out once you're done. He's fantastic!
To expand on question number 1.
Import and include are similiar but one thing to keep in mind with import is it does not increase you programs size. It simply goes to the location the instructions are stored and executes them. On the other hand when you use include, those libraries are mapped into your program. Thereby increasing your programs size. Someone please correct me if I'm wrong.


Topic archived. No new replies allowed.