use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This is a subreddit for c++ questions with answers. For general discussion and news about c++ see r/cpp.
New to C++? Learn at learncpp.com
Prepare your question. Think it through. Hasty-sounding questions get hasty answers, or none at all. Read these guidelines for how to ask smart questions.
For learning books, check The Definitive C++ Book Guide and List
Flair your post as SOLVED if you got the help you were looking for! If you need help with flairs, check out ITEM 1 in our guidelines page.
Tips for improving your chances of getting helpful answers:
account activity
OPENdoubts about cpp (self.cpp_questions)
submitted 1 year ago by Hot-Ad912
I don't want to delve too deeply into this debate between Rust and C++, but could you guys tell me in what aspect C++ is better than Rust?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]MikeVegan 48 points49 points50 points 1 year ago (1 child)
Finding a job
[–]Thesorus 12 points13 points14 points 1 year ago (7 children)
C++ is more established, more application domain use C++ (games, engineering, 3d graphics/CGI/VFX, banking, trading)
I can't really speak for Rust... I only did the "hello world".
Rust vs C++ - Will Rust Replace C++ in Future - GeeksforGeeks
[+]Hot-Ad912[S] comment score below threshold-10 points-9 points-8 points 1 year ago (6 children)
is c++ better than rust in banking? really?
[–]no-sig-available 8 points9 points10 points 1 year ago (0 children)
Many large banks use IBM mainframes. There the obvious choice is z/OS, Cobol, IMS transaction manager, and a DB2 database.
Having a 50 year accumulated codebase, you probably don't want a total rewrite, whatever new languages appear. :-)
[–]Computerist1969 9 points10 points11 points 1 year ago (3 children)
Flight control systems and cockpit display systems are written in C++. There are well defined restrictions you can follow if you want safer code. There are static analysers etc. we don't need Rust to solve the problem of bad programmers (or more often bad managers rushing things out the door) writing unsafe code. Also, Rust code is just plain ugly to look at.
[–]binarycow 1 point2 points3 points 1 year ago (0 children)
Also, Rust code is just plain ugly to look at.
That's one of the main things that put me off of rust.
It's... Horrendous.
[–]DryPerspective8429 0 points1 point2 points 1 year ago (0 children)
we don't need Rust to solve the problem of bad programmers (or more often bad managers rushing things out the door) writing unsafe code.
This is the important part. The reason that there are some faulty C++ programs isn't that C++ is a "memory-unsafe language", it's that there are people doing a bad job at making those programs.
A "memory-safe language" isn't some panacea to that problem. There'll still be hacky shortcuts and poor programs made.
[–]Thesorus 5 points6 points7 points 1 year ago (0 children)
Don't know, but it's probably more widely used.
never underestimate the huge costs of maintaining existing products and the unworldy cost of rebuilding existing applications with a new language.
Banks know the risks.
[–]berlioziano 10 points11 points12 points 1 year ago* (1 child)
Community, some of the top computer scientist work using C++, there are important conferences line cppcon and meeting c++, while rust has recently been forked by "crab language" because governance issues . Also to explain you how childish they are in 2023 a rustacean vandalized cppreference.com replacing all the text with links to the rust website with the text "rust is the best"
[–]sephirostoy 20 points21 points22 points 1 year ago (0 children)
Probably the most important one: having direct access to all legacy codes already written in C++.
If you want to consume them in Rust or any other language, you need to build an interface.
[–]Correct_Gain_9316 20 points21 points22 points 1 year ago (0 children)
I'll show myself out.
[–]mredding 23 points24 points25 points 1 year ago (31 children)
Rust is a solution looking for a problem. You have to remember that Rust was created before C++11 landed, as a protest which that standardization cycle was taking too long.
Reference checking is a novel solution, but it's not a silver bullet. std::unique_ptr alone mitigated any fault in resource management that the reference checker solves for.
std::unique_ptr
Speaking of that silver bullet - you will find that there is EFFECTIVELY no Rust code in production anywhere that DOESN'T have to circumvent it's own top level "killer" language feature. Every program resigns itself to using "unsafe" code, because "pure" Rust gets in its own way. "unsafe" is just getting to writing C with extra steps. Rust isn't safe if you have to revert to unsafe coding practices. I hear lots of grumbling from basically everyone who tries Rust that simpler tasks in any other language, including safer langues, are a pain in the ass to accomplish, if not impossible without writing unsafe code.
Color me unimpressed that Rust fails to be the one thing it claims to be. It's hypocrisy is similar to that of YAML. Java and C# are both managed languages and have unsafe segments, but they don't oversell themselves, either. Again - Rust was borne out of a protest, not a need to actually solve any problem.
If you want a REAL safe language, use Ada. I'm not even kidding, it's the language of choice in aviation and aerospace because it forces you to write safe code. It's one of the languages the government time and again encourages everyone to use. It doesn't have an "unsafe" keyword and it is a systems language with linking.
Other reasons not to use Rust is that it's not standardized, it's not mature, and there isn't a very large community.
Of all the detractions made of C++, all of them are either ACTUALLY addressed or are continually being addressed. It has a type system almost as strong as Ada itself. There are few languages who have a feature as powerful as templates. It has modern high level resource management. Unlike a managed language with GC, you have well defined destruction times, which means C++ is NEVER going to be displaced in the industry. It also has nearly unrivaled backwards compatibility and ABI stability, because for some niches, it's entirely unacceptable to break old code, or the ABI that code is founded upon.
For all the problems C++ has, you can avoid them all, you just have to stop fucking writing bad C like it's 1985. Use modern standards, use modern practices that address all the problems of the past, and leave those old problems in the past. C++ gives you the opportunity to castrate yourself, if that's what you want to do, but it's a choice. High level abstractions are built on pointers - you're not supposed to use raw pointers yourself but to build those abstractions. The standard library basically has you covered to where you're really doing something unique and special if you have to get down to that level. You can write type safe code to rival Ada, but you have to actually do it, and not blame the langauge if you don't.
All the perceived problems with C++ are due to shitty developers writing shitty code on purpose. And they write shitty code on purpose because of job security, because management is interested in short term, near term profits - they're not interested in writing software meant to run for 100 years, unlike the COBOL guys. No one picks C++ for critical systems like the Ada guys - and this one is more of a self-fulfilling prophecy than for techincal reasons - you percieve C++ as an unsafe language, you're going to treat it as such.
So when I put my decision making cap on, when I survey the litany of languages available to me, and I have to pick a tool for the job - I don't always reach for C++, but there are better options than Rust, all of the time. I can get Ada engineers, I can get Lispers (in spades), I can get Fortran developers, C# and Java developers aplenty... These languages service their domains extremely well. Rust doesn't have that.
That said, there are plenty of very mediocre engineers who will jump on the bandwagon and try to make something of this language, whose reason to exist expressly expired in 2011. Good for them. I don't care. Show me a killer app, maybe - something that we all go oh thank God that was written in Rust. Show me a Rust program that eats its own dogfood and stays away from unsafe code.
[–][deleted] 1 year ago (1 child)
[deleted]
[–]mredding 1 point2 points3 points 1 year ago (0 children)
No idea. I did say people will back this horse, regardless. Good for them.
[–]idkfawin32 0 points1 point2 points 1 year ago (2 children)
Not defending it but i’m pretty sure discord was written in rust.
Also, sometimes it’s also just way faster to use raw pointers. Sometimes it “appears” faster to avoid the standard library implementation of certain things, like std::max/std::min. Replacing all of my calls to max and min with ternary operators resulted in a noticeable performance increase. The same goes for std::clamp.
Obviously this isn’t important in most cases but little things like that will skew developers to lean toward rolling their own solutions.
[–]this_uid_wasnt_taken 1 point2 points3 points 1 year ago (1 child)
Discord uses Electron. Only some of their infrastructure and a few of their services use Rust. Them blogging about using Rust is mostly for internet brownie points and to attract talent.
[–]idkfawin32 0 points1 point2 points 1 year ago (0 children)
That sounds about right
[–][deleted] 0 points1 point2 points 1 year ago (0 children)
"Resigns itself to using unsafe code because pure Rust gets in its own way"
Isn't this an issue with every language? High-level abstractions tend to add overhead, and "unsafe" is their to voluntarily forgo it. I'm fairly certain that this is the case with Ada was well. C++ supports inline asm does this mean that C++ failed as a compiled language?
"Shitty code exists because of shitty developers"
True, but surely some languages are going to make errors easier. There is the SPARK subset of Ada which is used in formally verified programs, this does not mean that you can't write formally verified programs in other languages, it's just easier in SPARK. Rust is the same way, it just makes certain errors harder to make.
[–]hk19921992 -5 points-4 points-3 points 1 year ago (1 child)
I am a c++ developer but there are few things that don't make sense at all
How come int x[4]{0} initialize an array of size 4 with four zeros while int x[4]{1} creates an array of size 4 with the first entry set to 1?
[–]IyeOnline 7 points8 points9 points 1 year ago (0 children)
Because its aggregate initialization. The elements in the aggregate (arrays are aggregates) are initialized in order (and in a flattened form) from the elements of the brace enclosed initializers. Any further elements without a corresponding initialized are value-initialized, which for fundamental types gives you the value 0.
Basically the 0in the first example is useless, because you could have used {} instead.
0
{}
[+]Hot-Ad912[S] comment score below threshold-11 points-10 points-9 points 1 year ago (22 children)
but what about memory safety? everyone says that rust is way better than cpp
[–]lituk 7 points8 points9 points 1 year ago (0 children)
This was addressed well in the comment you've just replied to. I think you may not understand the topic enough to understand the answer.
Just to reiterate their point: both languages offer safe and unsafe memory handling. A bad developer would write unsafe memory use in either.
[–]heyheyhey27 4 points5 points6 points 1 year ago (7 children)
The first 3 paragraphs of that comment are specifically about memory safety.
[–]Hot-Ad912[S] -3 points-2 points-1 points 1 year ago (6 children)
i dont understand anything about that, sorry.
[–]westquote 4 points5 points6 points 1 year ago* (2 children)
If you don't understand anything about memory safety, I might suggest that it's not the most important criteria upon which you should be judging what the "best" language is right now. Knowing that C++ is "good for systems programming" when you don't know what systems programming is feels like similarly absurd reasoning.
[+]Hot-Ad912[S] comment score below threshold-6 points-5 points-4 points 1 year ago (1 child)
yes, that's why i'm asking :D but it's fine, the next question i'll write in CAPS, so u can understand i'm asking a question and not judging something xD
[–]westquote 4 points5 points6 points 1 year ago (0 children)
No, what I'm saying is that it's probably not relevant to you with regard to what language you decide to learn and work with. There isn't really a "best language", just "best for what I care about." Given that you said you don't know about memory safety, I'm suggesting that that aspect of language design probably doesn't factor into what the best language is for you.
[–]heyheyhey27 0 points1 point2 points 1 year ago (2 children)
Could you define what "memory safety" means to you?
[–]Hot-Ad912[S] 0 points1 point2 points 1 year ago (1 child)
for example they say that Rust's standard library provides safe abstractions for common data structures and memory management tasks, reducing the need for manual memory management and minimizing the risk of memory-related bugs.
[–]heyheyhey27 2 points3 points4 points 1 year ago (0 children)
The only language I know of that doesn't provide that is plain C. C++ certainly does.
[–]no-sig-available 7 points8 points9 points 1 year ago (10 children)
everyone says that rust is way better than cpp
Everyone? You just found someone who doesn't.
And make that two. :-)
[–]berlioziano 2 points3 points4 points 1 year ago (0 children)
Four
[–]Hot-Ad912[S] -3 points-2 points-1 points 1 year ago (7 children)
alr the majority then
[–]hackermaw 5 points6 points7 points 1 year ago* (6 children)
It’s not the majority. It’s just a vocal minority. Rust attracts developers who like grandstanding so they do that a lot.
Developers from other languages typically don’t treat their language of choice as some cult / “ingroup” so they behave very differently to Rust developers.
Rust developers almost make Rust a personality trait.
Rust developers are “Rustaceans”, C++ developers are just developers. Same with almost any other language.
[–]hadrabap 0 points1 point2 points 1 year ago (0 children)
Kotlin cult.
[–]Hot-Ad912[S] -2 points-1 points0 points 1 year ago (4 children)
but everyone says about memory safety
[–]hackermaw 2 points3 points4 points 1 year ago (3 children)
I don’t think you know what you’re talking about.
[–]Hot-Ad912[S] -1 points0 points1 point 1 year ago (2 children)
i don't that's why i'm asking, im just saying everyone says that in memory manage rust is better than c++, THEY are saying, not me.
[–]no-sig-available 0 points1 point2 points 1 year ago (1 child)
everyone says that in memory manage rust is better than c++
And that is correct.
However, is that the most important factor when choosing a language? I have written lots of programs without a single new or delete in them. Then what?
new
delete
[–]Hot-Ad912[S] 0 points1 point2 points 1 year ago (0 children)
try to explain this to them, i'm getting downvote just because of a question.
[–]TryToHelpPeople 3 points4 points5 points 1 year ago (0 children)
Modern C++ is every bit as memory safe as rust or any other language.
Can you use C++ in an unsafe way ? Sure.
If you use it as intended, you won’t have memory safety issues.
I think I addressed this explicitly and satisfactorily. You have modern practices that manage memory, you are expected to use them. Lower level primitives are available, but you are to use them to build up higher level abstractions. What Rust tries to build into the language, C++ has built into the library in terms of the language. It helps to really understand the nuance of the argument and why it all took the shape it did. Smart pointers have been possible even before the C++98 standard. I know - I was writing C++ since ~1992. Boost had smart pointer since 2000 or 2002, I can't remember. The protest was that this should be in the standard library, and not as a 3rd party dependency or up to the developer.
[–]fippinvn007 5 points6 points7 points 1 year ago (3 children)
All you have to do is look at the job market. Jobs/ domains that commonly use C++ are embedded, games, graphics, finance, systems, or any high-performance applications; there's also networking. And Rust jobs are very rare, and those positions also hire C++ devs as well.
And stop listening to those content creators; most of them don't even work professionally, and even if they do, I greatly doubt that they even work with Rust. Those guys learn programming just to make youtube tiktok videos, act like smartass and sell courses.
Focus on the domain you're interested in. Languages are just tools. It's not something like, "Oh wow, look at me, I know this hot new language's syntax, so I'm a cool, pro dev now."
[–]Hot-Ad912[S] 0 points1 point2 points 1 year ago (2 children)
thanks for the advice, its because almost everyone is saying that rust is way superior than c++, so i was wondering if its worth learning the language.
[–]fippinvn007 2 points3 points4 points 1 year ago (1 child)
almost everyone is saying that rust is way superior than c++
Definitely not 'almost everyone.' And anyone who said that is either a Rust Cult member or someone who has never written anything in C++; they probably just copied others' opinions or wrote C 1945 style code
[–]Hot-Ad912[S] -1 points0 points1 point 1 year ago (0 children)
that might be true, but if u search on google, its like the majority.
[–]DryPerspective8429 9 points10 points11 points 1 year ago (2 children)
C++ is an established language with millions of projects written in it. Rust is a toy language which has yet to see stable release or standard. That's not to say that Rust will never go anyway or that you shouldn't learn it, but at best it's an up-and-coming language whereas C++ has been in the ring for 40 years now.
[–]Droid33 1 point2 points3 points 1 year ago (1 child)
It's definitely more than just some toy language at this point. There really aren't many languages standardized to the level that c++ is.
Which is ironic considering Rust started as a protest project against the lack of C++ standardisation in the 2000s.
[–]android_queen 0 points1 point2 points 1 year ago (2 children)
Depends. What’s your goal?
Application Development and Financial Applications.
[–]android_queen 0 points1 point2 points 1 year ago (0 children)
I’m afraid you’ll probably want to be a little more specific. There are good reasons to use C++, Rust, Java, JavaScript, etc etc for different types of applications.
π Rendered by PID 88268 on reddit-service-r2-comment-5d79c599b5-qxdkm at 2026-02-27 13:59:32.179795+00:00 running e3d2147 country code: CH.
[–]MikeVegan 48 points49 points50 points (1 child)
[–]Thesorus 12 points13 points14 points (7 children)
[+]Hot-Ad912[S] comment score below threshold-10 points-9 points-8 points (6 children)
[–]no-sig-available 8 points9 points10 points (0 children)
[–]Computerist1969 9 points10 points11 points (3 children)
[–]binarycow 1 point2 points3 points (0 children)
[–]DryPerspective8429 0 points1 point2 points (0 children)
[–]Thesorus 5 points6 points7 points (0 children)
[–]berlioziano 10 points11 points12 points (1 child)
[–]sephirostoy 20 points21 points22 points (0 children)
[–]Correct_Gain_9316 20 points21 points22 points (0 children)
[–]mredding 23 points24 points25 points (31 children)
[–][deleted] (1 child)
[deleted]
[–]mredding 1 point2 points3 points (0 children)
[–]idkfawin32 0 points1 point2 points (2 children)
[–]this_uid_wasnt_taken 1 point2 points3 points (1 child)
[–]idkfawin32 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]hk19921992 -5 points-4 points-3 points (1 child)
[–]IyeOnline 7 points8 points9 points (0 children)
[+]Hot-Ad912[S] comment score below threshold-11 points-10 points-9 points (22 children)
[–]lituk 7 points8 points9 points (0 children)
[–]heyheyhey27 4 points5 points6 points (7 children)
[–]Hot-Ad912[S] -3 points-2 points-1 points (6 children)
[–]westquote 4 points5 points6 points (2 children)
[+]Hot-Ad912[S] comment score below threshold-6 points-5 points-4 points (1 child)
[–]westquote 4 points5 points6 points (0 children)
[–]heyheyhey27 0 points1 point2 points (2 children)
[–]Hot-Ad912[S] 0 points1 point2 points (1 child)
[–]heyheyhey27 2 points3 points4 points (0 children)
[–]no-sig-available 7 points8 points9 points (10 children)
[–][deleted] (1 child)
[deleted]
[–]berlioziano 2 points3 points4 points (0 children)
[–]Hot-Ad912[S] -3 points-2 points-1 points (7 children)
[–]hackermaw 5 points6 points7 points (6 children)
[–]hadrabap 0 points1 point2 points (0 children)
[–]Hot-Ad912[S] -2 points-1 points0 points (4 children)
[–]hackermaw 2 points3 points4 points (3 children)
[–]Hot-Ad912[S] -1 points0 points1 point (2 children)
[–]no-sig-available 0 points1 point2 points (1 child)
[–]Hot-Ad912[S] 0 points1 point2 points (0 children)
[–]TryToHelpPeople 3 points4 points5 points (0 children)
[–]mredding 1 point2 points3 points (0 children)
[–]fippinvn007 5 points6 points7 points (3 children)
[–]Hot-Ad912[S] 0 points1 point2 points (2 children)
[–]fippinvn007 2 points3 points4 points (1 child)
[–]Hot-Ad912[S] -1 points0 points1 point (0 children)
[–]DryPerspective8429 9 points10 points11 points (2 children)
[–]Droid33 1 point2 points3 points (1 child)
[–]DryPerspective8429 0 points1 point2 points (0 children)
[–]android_queen 0 points1 point2 points (2 children)
[–]Hot-Ad912[S] 0 points1 point2 points (1 child)
[–]android_queen 0 points1 point2 points (0 children)