r/CodingForBeginners • • 3d ago

Day 5 of learning C++(first program)

Post image

Today , i finally completed my 1st module on learncpp.com

Learnt literals , operators , expressions made two programs(only took ss of one Program)(and yeah I added new line character afterwards)

Well as I know some coding so it was pretty easy

Tbh the hardest part was to figure out what CMakeList is in CLion

Spend more time in figuring and setting that up rather than coding

+ If anyone know how to like automatically add executable in CMakeList rather than adding manually , well adding manually is not a problem tho but still

Tomorrow will be hectic day(college assignments and practicals) still will try to do some coding.

76 Upvotes

15 comments sorted by

3

u/kutac56 3d ago

You can do int x; instead of int x {};, you are using namespace std and then still typing std:: and you also don't need cmake as that is mainly for cross platform building which is not necessary for such simple things (compile with g++ foo.cpp -o foo)

2

u/samosa285 3d ago

Tbh I didn't know about what using namespace std does I was just messing around And about cmake without adding it CLion was saying that executable file cannot be created blah blah

1

u/[deleted] 2d ago

Have using namespace std just allows you to use the comment and statements without needing to use std. I don't know the full capabilities of it, but if you use namespace, you don't need std.

But yeah, using the -o is pretty cool if you want to make your own file names, without having to use ./a.out

2

u/Tiaoshi 3d ago

Nice work, though keep in mind, because you are using namespace std, you don’t need to add std:: in front of anything within the std library. Though if you wish to continue to do so, there is nothing wrong with it, just can save you a bit of typing by omitting it (while having “ using namespace std; “

1

u/samosa285 3d ago

Tbh I didn't know about what using namespace std does I was just messing around Still thanks!!!!

1

u/Psilocybe_Fanaticus 3d ago

Why are you using std::cout when you are already using “using namespace std”?

1

u/samosa285 3d ago

Tbh I didn't know about what using namespace std does I was just messing around

1

u/Psilocybe_Fanaticus 3d ago

It pretty much removes the need to type std::cout
If you use multiple libraries (in the future), do not use this. Always write it out and completely omit “using workspace std”

1

u/samosa285 2d ago

Ohkiee

1

u/Traditional_Vast9419 3d ago

CMake is just a build system. I'd recommend just using Make or compiler commands until you actually have a program that's ten thousand lines long.

1

u/samosa285 3d ago

Ohh will figure out that later

2

u/AntiCitizen6 3d ago

Nice work! Good job using comments!

1

u/Objective_Buy_7235 3d ago

Why does declaration of x have empty braces?

2

u/Hkiggity 3d ago

In c++ it’s used for value initialization. Which is useful for many reasons.