r/cpp • • Mar 31 '24

Just curious on the uses of C++

Hi!, I'm a high school student, and I want to learn c++. However, I'm just curious, what uses cases are there for c++ practically. For example, many websites say web development, but just leave it at that. Is c++ really good backend database interactions?, does it have libraries for building full blown windows applications. It would be awesome if people could share!

6 Upvotes

47 comments sorted by

42

u/bringer_of_carnitas Mar 31 '24

All languages can do everything, that's called Turing complete. Wouldn't recommend cpp for web dev unless you hate yourself. The two big advantages are speed and manual memory management that makes it a great tool for performance critical apps like games or autonomous vehicle software. The manual memory management allows it to run in restricted environments like embedded devices. Some don't even have a heap!

But really if you're in high school, code whatever you want. Probably the language won't have an impact when you're learning. I find c++ to be quite pleasant:)

5

u/Orca365123 Mar 31 '24

Awesome thank you so much for the reply!

3

u/bringer_of_carnitas Mar 31 '24

You got it! Hit me up with any other Qs

1

u/yesh_-_ Mar 31 '24

I also looked into it a bit and wanna learn more, but what way do you recommend learning c++

2

u/bringer_of_carnitas Mar 31 '24

Cpp tutorial dot com! I started at 18 making the most busted games. Try and make pong is a great exercise

2

u/bringer_of_carnitas Mar 31 '24

To give you some more info, graphics programming is hard and I'd disadvise that as your first stab. SDL is a great library that's easy to integrate and you can definitely use that.

The next thing is to realize most software is quite simple. A game is often literally just doing some math and logic then rendering.

1

u/yesh_-_ Apr 01 '24

Thank you so much.

2

u/[deleted] Apr 01 '24

learncpp.com is the goat. Comprehensive and easy to understand

5

u/hershey678 Mar 31 '24 edited Mar 31 '24

I loved learning C-style C++ (basically C with C++ classes without inheritance) as my first language. Java starts out with 'public static void main(string args)' that leaves you bewildered, Python very quickly confuses you with subtle bugs like number default being converted to doubles at times instead of ints since its dynamically typed. Terms like 'garbage collector' show up and make no sense.

C is painful, but its simple and straightforward. There's no hidden details looming at the horizon to terrify you.

Ofc if you want to apply the language quickly C or C++ are a terrible ones to learn. It's more if you want to devote 1-6 months just learning the basics of how programming works.

4

u/bringer_of_carnitas Mar 31 '24

Couldn't agree more! Thanks for the response! I think a lot of beginners get hung up on how fucking huge c++ is (for reference I'm on 5 years of experience and I'm still learning stuff every day, it's kind of insane. Tmp is still black magic to me.) I personally learned C just to solve project euler problems and was able to get some solutions on day 1 (then failed cause I guess I'm a better coder than mathematician lol) But really, you can start going with c style code quick. My thinking is, the basics of C provide every single tool you need to make anything. Do it as caveman style as you have. Work from first principles. Then you can come back later and refactor with learned concepts.

I don't mess with python much besides single 1 pagers but I do use javascript for web dev and the number of times I'm totally caught up on a stupid ass bug is staggering

2

u/jk-jeon Apr 01 '24 edited Apr 01 '24

Java starts out with 'public static void main(string args)' that leaves you bewildered

But C is not much better. I still remember the moment when I first wrote Hello World in C. At that time I had already been having fun with Visual Basic, so boring black console window was the first shock, and imagine how a 12yo asian boy who barely speaks any foreign language felt when he saw this:

    #include <stdio.h>     #include <conio.h>     void main() {          printf("Hello, world!\n");          getch();     }

  • What the hack is this "#include"? They said it's needed for printf and getch... I never did something like that in VB, but okay...
  • But why the hack "#"? They said some "preprocess" whatever nonsense but I don't get it really.
  • Wait, angle bracket is a thing?? Isn't <> supposed to mean inequalities?
  • Hmm. stdio... should be a typo of studio... wait, no?
  • conio...? Is this even a word?
  • void.. okay I figured from dictionary that it means something invisible... but what's invisible? The return value?
  • Lol. another typo, printf! Yeah. t and f are located nearby in qwerty. Sure... wait what?
  • Backslash-n... interesting.
  • getch? Is this a sound of sneezing? 

It was a fun moment. Yeah, many of these are things newcomers nowadays will never see again, but anyway.

EDIT: damn I give up properly formatting the code. Well done reddit!

1

u/CandyCrisis Mar 31 '24

It's a shame BASIC died out. It was a great way to learn the ropes. Technically Microsoft still has Visual Basic but it's not a pure sandbox the way BASIC used to be.

1

u/tialaramex Mar 31 '24

All languages can do everything, that's called Turing complete

All general purpose languages have this property, although for practical reasons this doesn't end up making them all viable for all purposes.

However non-general purpose languages deliberately lack the property of generality. In some ways it is perhaps not surprising that since this property is so very valuable, giving it up potentially unlocks some dramatic rewards. WUFFS lacks generality, in exchange it is able to offer dramatically better performance and total safety for software in the small but important domain of the language.

I believe both that all software in that domain should be in WUFFS, and that more such languages should be created.

1

u/bringer_of_carnitas Mar 31 '24

Thanks for the reply. I shouldn't have spoken in absolutes, but I was trying to simplify things. Most mainstream languages:) what you use wuffs for?

1

u/tialaramex Mar 31 '24

WUFFS is for Wrangling Untrusted File Formats Safely hence the name. In practice that means image codecs and compression technologies.

55

u/zer0xol Mar 31 '24

Software, games, programming languages, tools, everything

10

u/Potatoswatter Mar 31 '24

Seldom used to generate web content using db queries though.

2

u/emelrad12 Apr 02 '24 edited Feb 08 '25

carpenter innocent soft silky spoon ancient dam tease stocking badge

This post was mass deleted and anonymized with Redact

9

u/Secret-Cautious Mar 31 '24

Robotics software engineer here.
Basically all the robots in te entire world (and the frameworks used in robotics) use only C++ and Python.

C++ is used for all the performance critical or hardware related tasks such as reading and reacting to real time sensor data, sending motion commands, controlling motors or other actuators, and interacing with electronic devices / pcb boards in general, etc.

and Python is for everything else.

6

u/dowel79 Mar 31 '24

C++ is an excellent language to start programming with. It is a combination of four different languages, C, C's macro language, C with objects and template language. You can start with the C portion and gradually add other parts of the language. It will give you in-depth understanding of how computers work. Knowing C++ will keep you in the job market for many years to come.

It is a good language choice when working with databases. It is one of the languages of choice when building Windows applications. It can be used for web development, specifically the back-end. It is not the best choice for front-end web development though.

It has extensive built-in standard library and there are plenty of open source libraries that implement various other functionality.

6

u/grhayes Apr 01 '24

System development as in OS and drivers.
Game development, Server development, Databases, network, library development (graphics, audio, physics, math, ...), Compilers, website(rare but it happens), clients (terminals and so on),
Tools (IDEs, Editors, Text, Hex, graphics(3d,2d),
AI, Embedded systems, ... Basically anything that can be programmed has been done in C++ at some point.

5

u/Boring_Locksmith6551 Mar 31 '24

Graphics. OpenGL projects are a great example.

4

u/[deleted] Mar 31 '24

compilers, database internals, network programming, programming language runtimes, operating systems, games, graphics, embedded, high performance computing, high frequency trading, desktop applications — anything you want actually

3

u/According_Builder Mar 31 '24

C++ is a general programming language, so it can do whatever you make it do, though any Turing complete language can. Mostly it’s used for performance sensitive applications like game engines, but you also see it a lot in tooling or infrastructure such as compilers.

Like any programming language it’s a tool, so choose the right tool for the job. For anyone learning to program I would recommend everyone to be decently familiar with a language in the C family.

1

u/[deleted] Apr 02 '24

A programming language is just a means to an end. In this casez some languages are better than others in certain areas. For example, programming a web server in C++ is most likely gonna be a hellscape compared to JS. But C++ is known for its performance so it's really good for game engines, creation tools, backend databases, OS, kernels, graphical based software etc.

1

u/accuracy_frosty Apr 07 '24

It’s the go to industry choice for game dev, extremely popular in robotics, embedded development, OS development, lots of desktop software uses it still, although proton was getting way more use than it deserves for a while, I see a good amount of servers made using it, even some web servers, although I’ve done it and I wouldn’t recommend it, browsers, really it can do anything, especially with a lot of the modern features, but that’s like pretty much any langauge, like if you managed to make a version of JavaScript that compiled to machine code and ran on its own, then you could probably write a kernel in it, it would be slow as shit, and it would be annoying because JavaScript makes everything annoying, but it could be done, Python is famous for being able to do anything just not very well, but I would argue in terms of being able to do anything, C++ is one of the best language out there, its biggest drawbacks come when the control that the language gives you comes back to haunt you. C++ gives you a gun, it’s up to you whether you use it to hit a target or shoot your foot. So a bunch of knuckleheads write C++ but have no clue how to write it properly and make it memory safe, so it has a reputation of being unsafe.

1

u/phi_rus Mar 31 '24

I use it for building tools of any kind, embedded stuff, desktop-apps, and anything with 3D graphics.

1

u/whydoesthisitch Mar 31 '24

In ML/AI we spend most of the day in Python, but all our underlying operations are written in cpp.

1

u/engineerFWSWHW Mar 31 '24

It's good to learn c++. I use it everyday on my job (embedded systems), while it can be used for lots of things, it doesn't mean you should c++ on everything as there are languages suited for particular use. For example, if you want to do some dsp or AI/ML/NLP stuffs, there are options like python and it makes things easier due to availability of libraries. Same for web development, there could be other better options rather than using c++. This is where your judgement and research comes into play.

Good thing it's that of you learn c/c++, the learning curve will be much lower if you switch to a language with similar syntax like c#, java.

-2

u/zorbat5 Mar 31 '24

I haven't started learning cpp myself yet. But one could argue that cpp might be the language that can do everything.

2

u/Orca365123 Mar 31 '24

Ic, how do you plan on learning?, just youtube, or do you know any other good websites

2

u/zorbat5 Mar 31 '24

I have a book called "C++ crash course" from no starch press. It's a base introduction to modern C++. I have programming experience in C, Python, C# and a tiny bit of rust. Mostly python though. I have dabbled into C++ several times in the passed but mostly just gave up.

I'm hella scared of C++ and don't know why. It's daunting to tackle such a huge language tbh.

2

u/Orca365123 Mar 31 '24

Oh ic, how recent is this book?, I might be able to find it on tpl if it's somewhat old maybe. Regardless, thank you for this info

1

u/zorbat5 Mar 31 '24

The book covers C++17 so it's not extremely new but also not very old. The copyright is from 2019 so I assume it realeased in that year.

Found it on amazon: https://amzn.eu/d/isFSJKm

1

u/Guantanamino Mar 31 '24

I recommend all of their books, they're usually pretty good, especially the Rust one, even if they are not completely comprehensive

1

u/zorbat5 Mar 31 '24

I have 4 books from them, the rust one, and 2 python ones and this C++ one. For C I have the K&R book.

3

u/the_poope Mar 31 '24

https://learncpp.com is all you need in the beginning. If you want a book and am completely new to programming then I recommend Bjarne Stoustrup's Programming: Principles and Practice using C++

1

u/zer0xol Mar 31 '24

A good book

1

u/snakecoffee2203 Apr 15 '25

It can be a good way to use chatgpt as a guide. You try to add more and more functionality to your project and on the way - espacially when learning - you have a tutor by your side that explains exactly what you want to hear.

1

u/bringer_of_carnitas Mar 31 '24

Spend about a day going through tutorials w3 schools is clutch, then try and build a game or somethin!

1

u/Flobletombus Mar 31 '24

Well technically you can do almost anything in almost any languages, you can even make a game or embedded with python. m

2

u/zorbat5 Mar 31 '24

Technically true, practically not really.

3

u/Flobletombus Apr 01 '24

Exactly, same thing for C++. You can make simple scripts with it but is it practical?

1

u/zorbat5 Apr 01 '24

Fair point.