r/cpp_questions • • Sep 01 '25

META Important: Read Before Posting

186 Upvotes

Hello people,

Please read this sticky post before creating a post. It answers some frequently asked questions and provides helpful tips on learning C++ and asking questions in a way that gives you the best responses.

Frequently Asked Questions

What is the best way to learn C++?

The community recommends you to use this website: https://www.learncpp.com/ and we also have a list of recommended books here.

What is the easiest/fastest way to learn C++?

There are no shortcuts, it will take time and it's not going to be easy. Use https://www.learncpp.com/ and write code, don't just read tutorials.

What IDE should I use?

If you are on Windows, it is very strongly recommended that you install Visual Studio and use that (note: Visual Studio Code is a different program). For other OSes viable options are Clion, KDevelop, QtCreator, and XCode. Setting up Visual Studio Code involves more steps that are not well-suited for beginners, but if you want to use it, follow this post by /u/narase33 . Ultimately you should be using the one you feel the most comfortable with.

What projects should I do?

Whatever comes to your mind. If you have a specific problem at hand, tackle that. Otherwise here are some ideas for inspiration:

  • (Re)Implement some (small) programs you have already used. Linux commands like ls or wc are good examples.
  • (Re)Implement some things from the standard library, for example std::vector, to better learn how they work.
  • If you are interested in games, start with small console based games like Hangman, Wordle, etc., then progress to 2D games (reimplementing old arcade games like Asteroids, Pong, or Tetris is quite nice to do), and eventually 3D. SFML is a helpful library for (game) graphics.
  • Take a look at lists like https://github.com/codecrafters-io/build-your-own-x for inspiration on what to do.
  • Use a website like https://adventofcode.com/ to have a list of problems you can work on.

Formatting Code

Post the code in a formatted way, do not post screenshots. For small amounts of code it is preferred to put it directly in the post, if you have more than Reddit can handle or multiple files, use a website like GitHub or pastebin and then provide us with the link.

You can format code in the following ways:

For inline code like std::vector<int>, simply put backticks (`) around it.

For multiline code, it depends on whether you are using Reddit's Markdown editor or the "Fancypants Editor" from Reddit.

If you are using the markdown editor, you need to indent every code line with 4 spaces (or one tab) and have an empty line between code lines and any actual text you want before or after the code. You can trivially do this indentation by having your code in your favourite editor, selecting everything (CTRL+A), pressing tab once, then selecting everything again, and then copy paste it into Reddit.

Do not use triple backticks for marking codeblocks. While this seems to work on the new Reddit website, it does not work on the superior old.reddit.com platform, which many of the people answering questions here are using. If they can't see your code properly, it introduces unnecessary friction.

If you use the fancypants editor, simply select the codeblock formatting block (might be behind the triple dots menu) and paste your code into there, no indentation needed.

import std;

int main()
{
    std::println("This code will look correct on every platform.");
    return 0;
}

Asking Questions

If you want people to be able to help you, you need to provide them with the information necessary to do so. We do not have magic crystal balls nor can we read your mind.

Please make sure to do the following things:

  • Give your post a meaningful title, i.e. "Problem with nested for loops" instead of "I have a C++ problem".
  • Include a precise description the task you are trying to do/solve ("X doesn't work" does not help us because we don't know what you mean by "work").
  • Include the actual code in question, if possible as a minimal reproducible example if it comes from a larger project.
  • Include the full error message, do not try to shorten it. You most likely lack the experience to judge what context is relevant.

Also take a look at these guidelines on how to ask smart questions.

Other Things/Tips

  • Please use the flair function, you can mark your question as "solved" or "updated".
  • While we are happy to help you with questions that occur while you do your homework, we will not do your homework for you. Read the section above on how to properly ask questions. Homework is not there to punish you, it is there for you to learn something and giving you the solution defeats that entire point and only hurts you in the long run.
  • Don't rely on AI/LLM tools like ChatGPT for learning. They can and will make massive mistakes (especially for C++) and as a beginner you do not have the experience to accurately judge their output.

r/cpp_questions • • 58m ago

OPEN why doesn't local variable reference the element of the vector

• Upvotes

float current = 0.0f;

WrapPanel::Line& currentLine = lines.emplace_back();

currentLine.first = 0;

for (auto* child : flowChildren) {

UI::Size desired = child->desiredSize;

if (desired.width + current > primaryLimit && currentLine.count != 0) {

size_t count = currentLine.count;

// WrapPanel::Line* a = &lines.emplace_back();

//lines.emplace_back();

//currentLine = lines.emplace_back();

lines.emplace_back();

currentLine = lines[lines.size() - 1];

currentLine.first = count;

currentLine.first = 356;

//debug point here

}

the variable 'first' of last element of std::vector<WrapPanel::Line> lines should be '356'.

currentLine acts like it creates local variable and references it after executing first "if (desired.width + current > primaryLimit && currentLine.count != 0)" when " currentLine = lines[lines.size() - 1];".

the value in currentLine changes but not the value in 'lines'.

my problem is at this line "currentLine = lines[lines.size() - 1];"

it should reference last element of 'lines' but it doesn't.


r/cpp_questions • • 2h ago

OPEN I began coding with C++, should I continue learning it or should I drop it and start something else?

2 Upvotes

I have always wanted to learn coding and make games, but I didn't know what to do and how to start. About 4 years ago, I saw Sololearn's ad on Youtube (I'm not advertising them). Desparate to learn, I installed it. First, it asked me a few questions regarding why I want to learn coding, what I'm going to use it for (web designing, game development, ...), etc. After answering them, I got suggested learning C++, so I did. I finished the introduction course and learned about half of the intermediate course (if I remember correctly, the last thing I learned was separate files for classes).

Recently, I found out via social media that C++ is the worst language to learn as your first language. I am pretty comfortable with the syntax, but I do sometimes forget complex things like pointers, constructors and deconstructors, etc, because I don't have the time to code often. I have made a lot of small projects, and I'm currently working on a terminal version of Minesweeper that outputs the game board in colored text and is played via inputting the X and Y coordinates of the tile that you want to open or flag (I don't know how to make buttons, or programs with separate windows in general.)

I wanted to know if I should continue learning this language or should I drop it and learn something else, like Python?

Also, I have recently started working with Git, and I find it pretty complicated and hard to use. It would be nice if someone told me whether I should continue learning and using it or if it is too early and I should finish learning the language first.

(P.S.: Many apologies for my imperfect English; I'm not so good at writing and speaking, as it isn't my native language.)


r/cpp_questions • • 1d ago

OPEN Best book for OOP in C++17 and beyond?

13 Upvotes

So a lot of people suggested I learn from a book,which I like cause reading is the way I actually learn stuff,allng with then testing what I read. Some books were mentioned but I want to know if there are any other good ones.


r/cpp_questions • • 19h ago

OPEN tool and ways to debug c++

2 Upvotes

as the title says, what are good practices and tools to debug c++? I am using already GBD but i dont like the terminal approach and the the amount of stuff i have to type, especially for larger code


r/cpp_questions • • 17h ago

OPEN Benchmark Methodology Feedback?

1 Upvotes

Alright, so given that we recently moved this repo over from our personal account to our organization account, we thought it might be helpful to get some constructive feedback on the methodology. Thanks in advance!
Here is the repo:
https://github.com/nihilai-collective/json-performance
The libraries being benchmarked are:
Jsonifier (Our own library - which btw simdjson has been using as a performance reference point in their own commits recently)
simdjson
Glaze


r/cpp_questions • • 1d ago

OPEN what is the best tool for coding in c++ aside from vscode on linux

14 Upvotes

r/cpp_questions • • 1d ago

OPEN Best traditional resources to truly learn proper, cross-platform, desktop app dev with C++?

2 Upvotes

I have an extensive SWE career, across several platforms and tech stacks (Unity/C# -> iOS/Swift ~> Vue/Node/TypeScript), though given the adverse challenges, extreme competition, and/or growing lack of opportunities, I've been thinking about specializing on something lower-level, more serious and demanding, and which may lead me to a more secure and valued job for a considerable time.

I have Mozilla, and particularly Firefox development in mind, given that it's the app I use the most everyday, that I value the foundation's mission and modus operandi, that they have and might still have open job positions in the upcoming months, and that C++ is still at the core of serious app dev, and hopefully not as prone to waver by the reckless impact of gen. ai.

That said, besides the official reference, which I'll definitely read through for starters, while writing pieces of code to put the concepts into practice, and of course, by forking the Firefox (and similar) repos, start delving into them, and eventually trying to fix bugs, which other resources, approaches, tools (not ai-driven), etc., would you recommend me to channel the learning toward the goal I have in mind?

Edit: or courses, perhaps? For instance, back in 2019 I learned a ton on iOS dev, which helped me secure the first related job, thanks to Paul Hudson's Hacking with Swift.


r/cpp_questions • • 1d ago

OPEN Opions about the book: C++ How to Program 11e (up to C++23) of Deitel

4 Upvotes

https://deitel.com/c-plus-plus-how-to-program-an-objects-natural-approach-11-e/

I've seen so many posts asking which C++ books or tutorials people should read, and almost all of them receive the same recommendation: learncpp.com. However, I've never seen anyone mention this book. Why is Deitel's C++ How to Program rarely recommended?

I skimmed through the table of contents, and it seems quite comprehensive. I've also read some of the chapters, and they're pretty straightforward. It covers some topics that aren't discussed on learncpp.com, such as concurrency and metaprogramming.

The only downside is the text colors, which are a little bit gaudy.

What are your thoughts on this book? Would you recommend it to beginners and intermediate learners?


r/cpp_questions • • 1d ago

OPEN What should I build or learn next in C++?

11 Upvotes

About 6 months ago, I asked here how to approach modern C++ after learning mostly C++11 at university.

Since then, C++ has become my favorite programming language. I've also grown to really enjoy C.

Now I'm looking for a new challenge. I'd love to explore systems programming and build something interesting, perhaps a compiler, a small operating system or something completely different.

What projects or topics would you recommend exploring next?

Thanks!


r/cpp_questions • • 1d ago

OPEN Best c++ books for both competitive programing and first time learning

0 Upvotes

I am a student . So c++ would be my first language and i want to learn it through books . But I can only afford one book in my budget . But if I need separate books for competitive programing and for first time learning please comment down below ( much appreciated). Thanks in advance


r/cpp_questions • • 3d ago

OPEN Which graphics library could you recommend?

29 Upvotes

I am buidling my own game engine, but im not sure which graphics library to use. i think using pure OpenGL might be too hard for me, i like the raylib examples but out of the box it looks a bit too stylized to the raylib theme, so is it possible to make it look the way you want? What about SDL, whats the developer experience with that?


r/cpp_questions • • 3d ago

OPEN Where to start learning C++?

20 Upvotes

Hi everyone! I want to start learning C++, but I’m not sure where to begin. As my first goal, I plan to build a simple 3D viewport to understand how everything works in practice. Could you please advise on where a beginner should start?


r/cpp_questions • • 3d ago

OPEN How to learn c++ effectively and be profficient in it?

35 Upvotes

Maybe you've heard this question before, but I want to know. I've been studying c++ for a month now, and I feel like I know some of the basics, but I know that I need a different approach. I feel like I just memorize it instead of getting it. I want to learn it truly,the right way. I write a lot of code cause I know thats the best but I fall short on the thinking like a programmer part. I want to lean c++ independently,then switch to ue5 and work on a game. I would love it if you would share your methods and links to some good c++ literature. I know I'm not dumb and I know it's not easy. I am not looking for a quick solution, just the right one.


r/cpp_questions • • 2d ago

OPEN How to get the unblurred backdrop behind a window for a refraction shader? (Win32, Windows.UI.Composition)

0 Upvotes

I'm building a macOS style dock for Windows as a side project. It's plain Win32 C++, one exe: https://github.com/Moryel/JustBetterTaskBar

The dock background is frosted glass right now. It's a window with WS_EX_NOREDIRECTIONBITMAP, a DesktopWindowTarget, and a sprite visual whose brush is a HostBackdropBrush with a saturation effect on top. Trimmed down, it's this:

```cpp
HWND wnd = CreateWindowExW(WS_EX_NOREDIRECTIONBITMAP | WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_NOACTIVATE,
L"GlassWnd", L"", WS_POPUP, 0, 0, 1, 1, nullptr, nullptr, hinst, nullptr);
BOOL t = TRUE;
DwmSetWindowAttribute(wnd, 17 /*DWMWA_USE_HOSTBACKDROPBRUSH*/, &t, sizeof t);

auto interop = compositor.as<ABI::Windows::UI::Composition::Desktop::ICompositorDesktopInterop>();
winrt::check_hresult(interop->CreateDesktopWindowTarget(wnd, true,
reinterpret_cast<ABI::Windows::UI::Composition::Desktop::IDesktopWindowTarget**>(winrt::put_abi(target))));

auto visual = compositor.CreateSpriteVisual();
auto geo = compositor.CreateRoundedRectangleGeometry();
visual.Clip(compositor.CreateGeometricClip(geo));
target.Root(visual);

auto backdrop = compositor.CreateHostBackdropBrush();
winrt::Windows::UI::Composition::CompositionEffectSourceParameter src(L"backdrop");
auto fx = winrt::make<SaturationEffect>(1.8f, src); // custom IGraphicsEffectD2D1Interop
auto brush = compositor.CreateEffectFactory(fx).CreateBrush();
brush.SetSourceParameter(L"backdrop", backdrop);
visual.Brush(brush);
```

That works fine. What I want now is something like Apple's Liquid Glass: lighter blur, and the content behind gets bent near the edges like a lens.

The problem is that HostBackdropBrush already gives me the backdrop blurred, so there's nothing sharp left to displace. I also couldn't find a displacement effect that CreateEffectFactory accepts.

These are the two options I can see:

  1. Capture the monitor area under the dock with Windows.Graphics.Capture and set WDA_EXCLUDEFROMCAPTURE on my own windows so they don't show up in it. Then run my own D3D11 pixel shader on the captured texture for the blur, the edge displacement and a rim highlight, and present it through a swap chain. My worries here: memory probably goes from ~12 MB to 40-60 MB, the yellow capture border might show up on some setups, and a constant capture loop just feels heavy for something that's always on screen.
  2. Skip real refraction. Keep the HostBackdropBrush and just draw highlights and gradients on top. Cheap, but it only looks "kind of" like it.

My actual questions:

- Is there any way to get the unblurred backdrop from DWM or Composition without capturing the screen myself?
- If capture is the only way, is running Graphics.Capture continuously in an always-on-top window reasonable performance-wise? Has anyone done it?
- And can the capture border be turned off reliably for an unpackaged Win32 app?

Thanks in advance.


r/cpp_questions • • 2d ago

OPEN Looking for C++17 API design feedback on my networking library

0 Upvotes

I've been developing LightnerX, a C++ networking library built on top of GameNetworkingSockets.

I recently migrated it from C++26 modules to C++17, which required reorganizing the public API into traditional headers and source files.

The library provides client-server networking, connection management, message batching, and an interpreter for a small semantic communication protocol called INER.

I'm trying to improve the API before adding more features, particularly in three areas:

Resource ownership: Client and Server manage their networking lifecycle, while applications control initialization, updates, and how components interact.

Error handling: Operations return lightnerx::Result, allowing callers to inspect failures without relying on exceptions for ordinary networking errors.

Modularity: Networking, connection management, and message interpretation are separate components.

I'm interested in whether these design decisions make sense from a C++17 perspective.

Are there any API patterns or ownership pitfalls I should reconsider? Would you approach error handling or component separation differently?

I'm not looking for a general project showcase. I'm mainly interested in feedback on the public interfaces and design.

Relevant headers: https://github.com/pietroth/LightnerX/tree/main/include/lightnerx

Any technical criticism is appreciated.


r/cpp_questions • • 4d ago

SOLVED Performance of std::vector

33 Upvotes

In the university we had to implement quicksort, the unsigned ints are stored in std::vector. I have accidentally discovered, that all algorithms, despite how students implemented them, are much faster when instead of directly accessing data from the vector like that:

arr[n]

we write:

unsigned int *a = arr.data()

and access that data by writing:

a[n]

But I can't understand why is that, in both cases it translates to one and the same: *(a + n)

The code is compiled on Clion IDE if that changes anything, no custom settings for compilation are used.

I can't directly share the algorithms for copyright reasons as they are not mine.


r/cpp_questions • • 4d ago

OPEN Is there any free interactive learning like rustlings/ziglings for cpp?

20 Upvotes

I find rustlings/ziglings to be really strong at helping me learn concepts and have it stick.


r/cpp_questions • • 3d ago

OPEN What is the best way to learn C++ for control theory implementation? Should I learn python or C++?

0 Upvotes

My background:

I'm a 5th year mechatronics engineering student that is good with matlab/simulink and is looking to expand my skills for my future career in automation/control/robotics.

I already know the basics of C++ from the course I took in college. Also, I am pretty good at 86 assembly programming. I heared that python is only used for simulations but that is what I use matlab/simulink for.


r/cpp_questions • • 3d ago

DISCUSSION Why C++?

0 Upvotes

C++ is a general-purpose, performance-focused programming language used across many different fields, and I'm really enjoying learning it. However, I keep seeing a lot of experienced developers criticize it heavily. Linus Torvalds famously trashed the language, even calling it a "horrible language":

"C++ is a horrible language. It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much, much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do nothing but keep the C++ programmers out, that in itself would be a huge reason to use C."

He basically called C++ developers idiots. Even though he made this comment years ago in 2007, to be exact, it's starting to make me doubt my choice. And it's not just Linus; other tech pioneers and plenty of people on Reddit talk negatively about C++ as well. Different people have different critiques about the language claims such as, it's memory unsafe, violates clean language design principles, and more.

So, are these critiques mostly aimed at older versions of C++, and did modern C++ (C++11 and beyond) actually fix these issues? What are your thoughts?


r/cpp_questions • • 4d ago

OPEN Looking for a beginner-friendly C++ book

1 Upvotes

I recently decided to dive into programming, and I picked C++ as my first language. I realize it's a tough and complex language, but I'm drawn to it because I find it really fascinating.

That said, I'm wary of getting overwhelmed by the advanced topics right from the start and ending up in a tutorial loop where I'm just stuck learning without actually creating anything.

With that in mind, I'm on the lookout for book recommendations that strike a balance, something that won’t bury me in every intricate detail, but will still help me learn enough to work on some cool and practical projects.


r/cpp_questions • • 5d ago

OPEN Which book is the best for learning systems programming and low level in Modern C++ (17/20)

37 Upvotes

I have done some systems programming in C and C-style C++ with some operator overloading. But I want to learn Modern C++ (17/20) too and keep on doing systems programming along with low-level dev, which books do you recommend for me to follow?


r/cpp_questions • • 5d ago

SOLVED Confused between using learncpp or a book ? if book reccommed me the best ones

4 Upvotes

I have studied basic python in my high school , i have some foding knowledge and i know c till pointers , should i ue learncpp for learning cpp or any book , if bookplease give me the best ones


r/cpp_questions • • 5d ago

OPEN Bluetooth pairing

0 Upvotes

Guys am trying to have a Bluetooth manager(connect multiple device on one Bluetooth) work using cpp the thing is am not that good at cpp any recommendations. I tried using ai for advice but holy sh*t it's making it worse


r/cpp_questions • • 5d ago

OPEN Is this possible?

12 Upvotes

I’m working on a game engine as a way to learn C++ and CMake. I’m attempting to create an editor for my engine, and I want to use ImGui. I’ve been going back and forth about whether I want ImGui on the engine or editor, but I think I want it on the engine because the engine owns the main loop, so it can just do the imgui frame lifecycle stuff. Also, if I ever decide to learn Vulkan and switch to it (unlikely), I don’t think I’d need to update the editor.

The problem with putting it on the engine is that the game will now have ImGui and this code running each frame, not actually doing anything. I’m sure this has little to no impact on performance, but I feel like it’s unnecessary?

Anyways, I’m wondering if it’s possible to make it so that if I run the editor, then the ImGui code runs otherwise, it’s stripped out. I know there is conditional compilation I just don’t know if that is something that can be done in this scenario?