r/cpp_questions • • Sep 01 '25

META Important: Read Before Posting

183 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 • • 6h ago

OPEN How should I go about learning C++ for low-level gamedev?

4 Upvotes

Good day,

I am an intermediate game developer coming from Unity, and I'd like to deepen my knowledge of game development. Let me tell you about myself first and how I got here.

Over the summer I've learnt a considerable amount. I've learnt about OOP. I can realize design patterns, refactor code according to SOLID principles, and write systems which are clean and scalable. I've come to realize that objects, such as classes and interfaces, aren't just magic words I put into the IDE. They're actual abstract objects which have their own properties and relationships between one another (I'm still in high school so I don't really know any comp sci theory other than what I use to create games). In June I've created a game featuring an AI which uses a complex Hierarchical State Machine governed my emotional dynamics and external events. My implementation of the State machine pattern allowed me to use it all over the game without issue or extra modifications.

I've also learnt about Data-Oriented Design. Over July I've gotten the feel for Unity's Data-Oriented Technology Stack. I've learnt to think in terms of ECS, be cognizant of the memory I'm using, and parallelize code. I've written an N-Body simulation which uses the Barnes-Hut algorithm. Coupled with multi-threading (Jobs) and the Burst compiler, the sim can handle ~100K bodies with collision at a presentable framerate.

In August I've joined a team to participate in the National Technological Olympiad in Russia to go to uni, so I know what "readable" code means, how to use version control and how to write professional, clean and beautiful code. However, that's besides the point.

As I've matured as a programmer, I learnt about the concept of low-level game development. I've come to realize that Unity isn't a magic box. Previously, I didn't even consider that there's something under the hood of the game engine. I just wrote code, clicked buttons, and it all just worked. However with time, I've come to realize that this isn't the case. Unity is yet another program which hides a considerable amount from me. I realized this mainly in July, when I needed to know how the CPU worked more-or-less (when things like cache lines and race conditions became important). Then I realized that I really am at the very tip of this metaphorical iceberg of programming, looking down at the deep water below.

Here's when I've learnt about C++. I know that this language is often regarded as the foundation of just about everything, including games. I've used it briefly before. Long ago, I've written a little Pong project with C++ and built it with CMake, having used SFML to render objects to the window. I've also used C++ to solve simple Codeforces problems, so I do have the rudimentary knowledge of input/output on C++. But that's about it. My aim is to use the language to learn about low-level game development, to "break free" from the game engine and expand the domain of my expertise (maybe to even write my own game engine in the future). I can learn the API of the language rather quickly (e.g. how to write lambdas, how to import libraries, anything I can already do in C#), however I know that's not all that I'll need.

I am aware of the gaps in my skills. I have the high-level knowledge, just not the low-level knowledge. Even though I know how to use DOTS to write parallelized, Data-Oriented systems, I can't really tell you how to resolve even a simple race condition, or what a memory leak actually looks like, or how the CPU and RAM are laid out, or how things actually work on the low level. Even though I can use the API Unity and C# provide to use OOP to write clean and modular code, I don't really know how a class actually works, what differentiates data types from reference types (other than "something, something, pointers, something, something"), and how things actually look like inside memory. Unity hid all those troubles from me. So I know that these gaps must be addressed for me to proceed in my learning journey. I learn fast though (as I've shown), so it's not that big of a deal.

Here's where I need your help. I know that to learn efficiently I first need a plan, a roadmap per se. Given my experience, how should I approach learning low-level gamedev on C++? What stuff do I need to learn about? And in what order? What is your advice?

I'd love to hear from you wonderful people.


r/cpp_questions • • 1h ago

OPEN How to master? What courses to watch?

• Upvotes

How can i write my own network stack? How can i code using linux syscalls and header. Idk what to do. Please help me im so confused. I got the basics of cpp btw


r/cpp_questions • • 2h ago

OPEN I am searching for a cpp "engine"

1 Upvotes

Hello, I have been using c++ for the last few months and I am pretty satisfied with it and I think that it is going to be and stay as my main language. I have looked at the alternatives like C#, GDScript, Rust etc. and want to get into game developement. My current issue is that i can't seem to find a good engine/framework. I tried Godot with GDExtension, but the implementation for c++ was quite tedious and not integrated - Unreal Engine is a bit too much functionality for me, as I only want to do simple games. Engines like Flax oder O3DE seem to unknown, so I am currently thinking about using a framework wich fullfills the tasks of an engine, like rendering, physics etc. I have used raylib and sfml before and managed to get a small architecture to run(mostly through a small render class, very limited in functionality). If anyone had similar issues finding something to work with c++, please do tell me your suggestion for what I could use


r/cpp_questions • • 12h ago

OPEN Qt Quick + QML GUI App Tutorial Series Suggestions?

3 Upvotes

I am a freshly minted C++ Qt developer in that I just completed an online course for C++ and the basics of the Qt framework within the past few days.

I am looking for video tutorials on how to build a GUI application using the Qt framework using Qt Quick and QML. For reference, I am not completely new to programming. I am a full-stack mobile and web developer who has been developing both types of applications for years. My tech stack in React (Next.js)/React Native on the front-end and pure Django or Django REST Framework + Django Channels on the backend.

What originally got me into web development was Corey Schafer's Django tutorial series which guided me through developing a web application using Django assuming I already knew HTML, CSS, and Python. That is when I learned that I learn best with YouTube video series I can follow along while the instructor explains what I'm coding. Is there any such series for Qt Quick and QML like building a notepad app? YouTube search results only turn up outdated tutorial series using Qt Widgets which IS NOT what I'm using and am avoiding because I want to construct the UI using QML files, not the widget picker.

Thanks in advance for your help!


r/cpp_questions • • 8h ago

OPEN IntelliSense marks an error where the compiler is fine (VCStudio 2022)

1 Upvotes

I have these three lines inside my constructor. I'm using C++23, configured through CMake. IntelliSense complains because SubCursor is non-copyable and non-movable:

function BooksReport::Group::Cursor::Cursor(BooksReport::Group::Cursor &&) cannot be referenced. It is a deleted function

If I understand correctly, copy elision should bypass copying in these examples:

    using SubCursor = BooksReport::Group::Cursor;

    subCursors.push_back(std::unique_ptr<SubCursor>(new SubCursor(booksReport->uniform.getCursor())));
    subCursors.push_back(std::unique_ptr<SubCursor>(new SubCursor(booksReport->nonUniform.getCursor())));
    subCursors.push_back(std::unique_ptr<SubCursor>(new SubCursor(booksReport->singles.getCursor())));

This implementation is due to the fact that SubCursor registers its address within the parent Group object upon creation. Normally a SubCursor is created during loop initialization and thus corresponds to an object on the stack. In this specific case I need objects stored in a list, hence my attempt to put them on a heap and store unique_ptr for easy memory management.

Like I said, the compiler is completely fine with this, but IntelliSense isn't. I hate red squiggly lines. Does anyone know if this can be solved?


r/cpp_questions • • 17h ago

OPEN C++26 template for loop std::span<T,N>

5 Upvotes

Hi, C++26 added "template for" operator , https://cppreference.com/cpp/language/template_for .
GCC 16.2 it supported. It works with std::tuple, std::array, but can't compile with std::span<T,N> fixed size.

How to achieve that, std::span<T,N> also worked with "template for" ?

https://godbolt.org/z/6s9MfzTeb

It be very useful for hand-by unroll loop.

I try specialize std::tuple_size, std::tuple_element, std::get for std::span<T,N> , but it don't helped.


r/cpp_questions • • 1d ago

OPEN Where to actually use pass by values/reference/Pointers ?

26 Upvotes

Our professor showed us this topic today but i can't Say ive understood It very well.

From the few examples he showed us, It felt like Just adding extra steps to a function rather than creating those straightfowardly.

When its a time id actually use those rather than not ? To prevent errors of some kind ?


r/cpp_questions • • 1d ago

OPEN Guidelines for constexpr

12 Upvotes

I’ve working with C++23 and I’m making some constructors/methods constexpr and seeing improvements in performance. So far so good. The problem is I don’t want to apply it ‘everywhere’. Is there a good source of advice , or anyone got any good tips?


r/cpp_questions • • 1d ago

OPEN Learning about threads. What happens here?

7 Upvotes

Hello, I just started learning about threading and learned that if you don't join or detach a thread, it will kill your program. Looking at the following code,

void my_func() {
  for (int i = 0; i < 100; ++i) {
    std::cout << i << ' ';
  }
  std::cout << std::endl;
}

int main() {
  std::thread{ my_func }; // A

  std::thread{ my_func }.join(); // B

  std::thread{ my_func }.detach(); // C
}

A does in fact kill the program. However, when I run this, I only get the output for my_func() once, and that output prints before A causes termination. I also only get the output for my_func() once when A is commented out.

Am I not seeing the output for C because the program just ends immediately after, so C doesn't have time to print anything out? What happens if I detach a thread and end the program before it finishes?

I did not compile with flags. I threw this in Visual Studio (non code) because it's convenient.


r/cpp_questions • • 1d ago

OPEN Efficient FIle IO on Linux

2 Upvotes

What path to take when parsing large files (on Linux Debian server, the KVM flavour)? Will std::fstream in binary mode do or do we have to look into APIs?

Apart from the performance, the app is memory sensitive, so where to store those read chunks while in a loop? Would a simple char[something] buffer do?

Finally, we would like to avoid those nasty reinterpret_cast<char*> constructs while reading, but are wondering if those are actually used in production? I should also add that the file sizes vary greatly.


r/cpp_questions • • 2d ago

OPEN Title: Looking for a Code Review for My C++ Chess Application

48 Upvotes

​

Hey everyone,

I've been working on SeaChess, a chess application with its own chess engine, and I'd appreciate it if some of you could take a look at the code and give me an honest review.

I'm currently trying to improve my C++ skills and prepare for a C++ developer job. I'd love to hear your thoughts on a few things:

What could I improve in terms of code quality, design, and overall implementation?

Is this a good project to include on my resume when applying for C++ developer roles?

What other projects, skills, or topics should I focus on to improve my chances of getting a C++ job?

I'm open to constructive criticism and would appreciate any advice, especially from people who work professionally with C++.

GitHub: https://github.com/TejasKayande/SeaChess

Thanks!


r/cpp_questions • • 1d ago

OPEN Yo , i have been looking for a decent or good open source / cracked c++ gui that i can use for my project. But i haven't been able to find a decent looking one. Could yall help please 🙏

0 Upvotes

Please help i have been searching for like a week now. And i cannot make a decent looking ui for my life.


r/cpp_questions • • 2d ago

OPEN C++programing

0 Upvotes

I am a student in high school in second year.I want to learn c++ autodidact


r/cpp_questions • • 2d ago

OPEN need guidance

4 Upvotes

hey everyone, i was planning to start the website learncpp.com, the fact is that ik some of the cpp and have coded around 300+ questions in cpp on lc and cf combined, its just that i want to learn everything in detail and sometimes i just keep discovering new things in cpp, whats the most effective way to do it from this website


r/cpp_questions • • 2d ago

OPEN Help with C++ Compiling (MinGW-64-GCC)

0 Upvotes

Hi there, so I’ve been trying to patch out a piece of code in The Sims Legacy Collection that disables the -debug_objects command line from being enabled, but both MinHook and CMake are giving me such a hard time that idk what else to do or where to ask… There are no tutorials AT ALL for compiling MinHook with MinGW-W64-gcc, only for Visual Studio (not Code!) which I can’t use because I’m on Arch Linux…

If anyone could advise me please I’d really appreciate it…


r/cpp_questions • • 3d ago

OPEN Compile time programming learning advice.

7 Upvotes

Hi all, can you please recommend me some resources that you have followed for compile time programming in modern C++ for eg: constexpr, consteval or template metaprogramming.
Is there some consolidated resource for the same ?


r/cpp_questions • • 3d ago

OPEN Network Classifier design in C++ (analog of Rust enum)

3 Upvotes

For those of you who saw the word “Rust” in the title, don't be alarmed. I don't want to start yet another holy war about which language is better. I'm here for some design advice.

Recently, I set myself the goal of writing a console-based Internet packet monitor. To my surprise, I found very few C++ projects whose source code I could study. But I did find one project that I liked, and that is https://github.com/matthart1983/netwatch. It’s written in Rust and is quite well-written (I don’t know Rust, but even I was able to understand some parts of the code, this is how I define "well-written").

One part of the code caught my attention more than the others. This part is located in the dpi folder. https://github.com/matthart1983/netwatch/tree/main/src/dpi

Essentially, the main things we have are the following:

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum AppProtocol {
    /// DNS query or response — first question's qname + qtype, plus the
    /// header RCODE on responses.
    Dns {
        qname: String,
        qtype: u16,
        /// Response code from the DNS header (`0`=NOERROR, `3`=NXDOMAIN,
        /// …). `Some` only when the QR bit marks this a response; `None`
        /// for queries.
        #[serde(default)]
        rcode: Option<u8>,
    },

I might be wrong, but I think it's called ADT (if I'm wrong, please forgive me—I'll correct the title of this post).

Another part is this

pub trait Classifier {
    /// `Some(protocol)` when this classifier recognizes the payload,
    /// `None` to fall through to the next classifier.
    fn classify(&self, payload: &[u8], is_tcp: bool) -> Option<AppProtocol>;
}

And finally, here are the following sections for each of the protocols:

pub struct DnsClassifier;

impl Classifier for DnsClassifier {
    fn classify(&self, payload: &[u8], is_tcp: bool) -> Option<AppProtocol> {
        if is_tcp {
            return None; // DNS-over-TCP exists; skip for now.
        }
        if payload.len() < HEADER_LEN + 1 + 4 {
            return None; // minimum: header + root qname(1) + qtype+qclass(4)
        }
        let qdcount = u16::from_be_bytes([payload[4], payload[5]]);
        if qdcount == 0 {
            return None;
        }

        // Header flags: QR is the high bit of byte 2; RCODE is the low
        // nibble of byte 3 (RFC 1035 §4.1.1). We surface the response code
        // only on responses (QR=1); queries report `None`.
        let is_response = payload[2] & 0x80 != 0;
        let rcode = if is_response {
            Some(payload[3] & 0x0F)
        } else {
            None
        };
// ... some lines here

My question is this: What would the design of the classes/structures look like if we were writing all of this in C++?

I'm curious to see what elegant, clean code for exactly the same task might look like in C++.

The first thought that came to mind was to simply write a protocol interface that included a `classify` method.

class Protocol {
public:
virtual ~Protocol() = default;

// note: return type of this function is void
// i don't know how to do it better
// maybe std::optional?
virtual void classify(std::span<std::byte> payload, bool is_tcp);
}

Beyond that, we simply have a bunch of derived classes for each protocol.

class DnsProtocol : public Protocol {
public:
constexpr auto HEADER_LEN = 12u;

virtual void classify(std::span<std::byte> payload, bool is_tcp) {
if (is_tcp) return;

if (payload.size() < HEADER_LEN + 1 + 4) {
            return; // minimum: header + root qname(1) + qtype+qclass(4)
        }
}
}

What do you think?


r/cpp_questions • • 3d ago

SOLVED Dangling ptr to out of scope variable?

0 Upvotes

Hi I am trying to play around with some code and made the following:

class Obj {
public:
Obj() : ptr{} {}

void set(int const& x) {
ptr = &x;
}

int const& get() {
return *ptr;
}

private:
const int* ptr;
};

int main() {
Obj obj;
{
int x = 5;
obj.set(x);
}

std::cout << obj.get() << std::endl; // prints 5
}

This compiles and runs even if I remove the const qualification from ptr, the return of get(), and the parameter for set(). Does it not abort or throw an exception if I access a dangling reference or pointer?

Update: thanks everyone!


r/cpp_questions • • 3d ago

OPEN Why clang and libcxx recieve so little contribution from the companies

40 Upvotes

Progress there is so incredibly slow, they don't even have full C++23 coverage at trunk and we are at the end 2026, so that's what? a 4 year old gap. Don't companies want better qol?


r/cpp_questions • • 3d ago

OPEN is there anyone that can help me install c++ on vscode

0 Upvotes

r/cpp_questions • • 4d ago

SOLVED I want to learn how to write C++ for work.

19 Upvotes

Nice to meet you. It’s been 10 years since I first started working with C++, but since I haven’t been able to land a job, my experience is limited to hobby projects. How can I write good code?

I suppose, unlike code written for work, hobby code is only meant to be understandable to the person who wrote it. How is that different from professional work?

I enjoy using libraries like raylib, dxlib, and SDL3.

I’d like to learn the techniques for preventing code from becoming a “spaghetti mess” in a professional setting.

I’ve looked up a lot of this on Gemini, but I’d like to hear some human opinions.

Translated with DeepL.com (free version)


r/cpp_questions • • 5d ago

OPEN Is c++ gonna have a good job market in the future?

108 Upvotes

AI rn isnt the best at c++ and although you cant hope that it stays bad forever but i was wondering if the job market was gonna be ok in the future for c++

i wanna keep learning graphics programming and hope it might get me a job one day

sorry if this post sounds dumb, idk what to do with my life


r/cpp_questions • • 4d ago

OPEN Correct way to test async code?

10 Upvotes

Lets say I have async code or some sort of timer or scheduler that calls a lambda later on some event, how do i test this in simple way in existing frameworks?

Is using futures or other sync mechanism the only way? or a simpler runloop/eventloop style facilities exist in test frameworks to simplify things?

For now looks like the test itself has to take on more theeading/orchestration/synchronization responsibilities.

For event driven and interactive apps, async execution would be common.


r/cpp_questions • • 4d ago

OPEN Web service

9 Upvotes

Which (fairly simple) C++framework would you recommend for a simple http server that binds to a hard-coded port and does a simple listen, read, write shebang on a server? We don't need nothing fancy or complex, we just want to avoid that native Linux sockets APIs boilerplate coding.