#im not great with cpp ive only ever use it for competitive programming lol.
Explore tagged Tumblr posts
Text
seeing as you know python ill try and give the python equivalents to these things.
an iostream is basically just something you can read from and write to. this may be a file or stdin and stdout (in python this is what you input from and print to). include is basically just import.
cout what you print to. the syntax cout << foo << bar; is basically the same as print(foo, bar) in python. (and the equivalent of x = input() is cin >> x)
... its not exactly the same though. you didnt ask what endl is but cout << foo is basically print(foo, flush=false, end=""). adding endl will append a newline and flush the buffer, making cout << foo << bar << endl equivalent to print(foo, bar). (endl ends the line)
an int is basically the same as an integer in python... but theres a min and a max. (you can basically always assume int is 4 bytes long and signed, meaning the min is -2^31 and the max is 2^31-1. the -1 is because of 0.)
a namespace is a collection of functions under one name - very similar to a module in python. so with python you may have math.sqrt and math.tan and similar, math would be the namespace. using namespace std is similar to from math import * in the sense you can just write sqrt instead of math.sqrt. if you werent using namespace std you would have to write std::cout instead of cout and std::endl instead of endl
(note: its similar in that you dont need to qualify the name, not in that you have imported everything from the standard library.)
okay i got a hello world script open in code::blocks and i am very lost
what does any of that even mean??? the fuck is a cout? what's a namespace? what does int mean in this context if not integer like in python? what is an iostream?
#i speak i ramble#if you have any other questions ill try and help.#im not great with cpp ive only ever use it for competitive programming lol.#if you dont know some of the python things i compared the cpp to. you now know something to experiment with in a familiar language!#coding
23 notes
·
View notes