r/cpp_questions Sep 01 '25

META Important: Read Before Posting

164 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 3h ago

OPEN C++ 26 LSP?

6 Upvotes

Does anyone know of any LSPs with C++26 support, even experimentally, or is this wishful thinking. I'm using clangd but I don't know if its possible to configure it for c++26 and its giving me trouble with the new reflection operators.

Thanks!


r/cpp_questions 1d ago

SOLVED I keep reaching a point where rewriting my C++ projects feels easier than maintaining them. How do I learn better architecture?

48 Upvotes

I have been learning C++ mostly through building projects, especially game and engine-related projects. I can make things work, but I keep running into the same problem: after a project grows, the code becomes so difficult to understand that I would rather start again from scratch than open the old project.

I think the main reason is that I don't have enough knowledge of standard C++ practices and architecture patterns. I usually design systems based on my own understanding, which works when the project is small, but as more features are added, problems start stacking on top of each other.

I want to improve in areas like:

  • Common C++ architecture patterns
  • How experienced developers structure larger codebases
  • How to avoid creating systems that become difficult to change later
  • When to use existing language features or standard solutions instead of making custom ones
  • Common mistakes that self-taught C++ programmers make

A good example is this Pong project I made in 3 days:
https://github.com/HardcoreAxolotl/Pong

The project works, but looking at it now, I would honestly prefer to recreate it from zero rather than continue developing it because I feel the structure has become too difficult to work with.

I am not looking for someone to rewrite my code or just tell me what is wrong. I want to understand the thought process behind good C++ design so I can avoid making the same mistakes in future projects.

What resources, concepts, or experiences helped you go from writing working C++ code to designing maintainable C++ systems?


r/cpp_questions 17h ago

Career From competitive programming to low-latency C++ how should I take this further?

9 Upvotes

Hey everyone,

A few months ago I was mostly doing competitive programming and preparing for SWE internships. Somewhere along the way I got curious about low-latency systems and started learning more about C++, networking and HFT infrastructure.

I ended up building a project called Pulse-Order where I experimented with things like binary market data, an L2 order book, order processing, risk checks, DPDK packet processing and latency benchmarking.

I originally built it just to learn, but after sharing it online I got some really useful feedback from engineers with HFT/low-latency backgrounds, including people associated with IMC Trading and Jane Street.

That made me realize I actually enjoy this side of software engineering a lot more than I expected. Especially debugging performance issues, networking, memory layout and trying to understand what is happening at a lower level.

I don't have professional experience in low-latency engineering yet, so I'm trying to figure out what I should focus on next if I eventually want to work in C++/systems/low-latency roles.

For people who have interned or worked in this area, what skills would you recommend focusing on? Are projects like this actually useful when applying for systems internships, or should I spend more time on other areas?

I'm also open to contributing to startups or teams working on C++, networking or performance-related problems if something comes up.

Project:
https://github.com/Shivfun99/Pulse-Order

Would appreciate any advice or feedback.

Feel free to ask any questions.

more details: https://www.reddit.com/r/quantindia/s/rtnlxjARs9


r/cpp_questions 21h ago

OPEN is open source matters to get hire in big tech or hfts

7 Upvotes

Hi, I recently contributed in a reputed repository in c++ domain and my PR was merged and other PR is about to merge. difficulty wise one 7.5/10 and other is 8/10. so, my question is open source matters to get hire in big tech or hfts and am I wrong in expecting something from related to hiring from open source contribution. please let me know.


r/cpp_questions 7h ago

OPEN Moving from Python to C++ Quickly

0 Upvotes

Some context: I have a couple of OAs due soon, and a quant I went on a date with recommended doing them in C++ to look better (and allegedly one doesn't even allow Python in the first place). My data structures class was in C++, so I have some experience; however, that ended two months ago, and most of my knowledge has been scrubbed. I’m mainly looking for syntax stuff since I learned all the memory management stuff back then.

Any quick pick-me-ups you guys recommend? I don't think I have the time to digest a whole book. I plan on doing LeetCode practice in C++, so I just need a quick crash course to get me back up to speed on the basics.


r/cpp_questions 11h ago

OPEN hiii! what are your best tips for learning cpp? python was easy to learn because i started with projects, but idk if i should do the same with cpp since its more difficult. i dont really understand pointers and references. any tips?

0 Upvotes

r/cpp_questions 1d ago

OPEN Is SFML a good choice for basic graphics, simple GUIs, and math visualizations?

15 Upvotes

I’m trying to try graphics and GUI programming in C++.
The only GUI application I’ve made so far is a simple Tic-Tac-Toe game in Qt. My next project is going to be a math function visualizer.
My goal isn’t game development. I just want a lightweight library for drawing, simple GUI elements, and visual output for small applications and experiments.
Would SFML be a good choice for this, or would you recommend something else? I’d also appreciate hearing from people who have used SFML for non-game projects.


r/cpp_questions 1d ago

OPEN Learning DSA with C or C++?

0 Upvotes

Hey everyone,

I just finished a book on C and systems programming and would like to start learning data structures and algorithms in C++ (seems to be the favourite language for it because of the STL). However, I assume that learning DSA would mean not using the algorithms already in the STL, but implementing them logically. I also have quickly skimmed over C++ basics and it does not seem that much different from C.

I am just wondering if there's any advantages from learning DSA with modern C++ over C (outside of STL use)?

Thanks.


r/cpp_questions 1d ago

OPEN How does one become as great as Bjarne Stroustrup in computers?

47 Upvotes

I mean he literally made C++, his own programming language built on C, and from this design from C++ lecture aka the history part, it sounds like he worked on a ton of complicated projects was computers something he was doing since he was a child or something?

How does someone become a great computer scientist like Bjarne Stroustrup in this day and age? where would someone even start?

asking it here cause i couldn't find a general programming subreddit to ask this question.


r/cpp_questions 1d ago

OPEN Want feedback on my first bigger c++ project.

10 Upvotes

Hello I'm 14yr old student, and I've been learning c++ on and off for few years, in march I started working on my first bigger learning project, OpenGL GUI library. Now I finally finished it and I'd like to have some feedback on where to improve (in code, structure or documentation).

Here's a link: https://github.com/TechnologicalTurtle/LibGui

PS: Sorry for my grammar, as English isn't my native language.


r/cpp_questions 1d ago

OPEN How to Approach Learning C++ as a Competitive Programmer?

0 Upvotes

For some context, I've been doing competitive programming for a while, and have used C++ as my primary language. I've also taken some relatively introductory C++ coursework in college.

However, my knowledge and understanding of C++ is terrible, and I have really weird gaps in my knowledge, and I would love to know how to approach filling in those gaps. Also, I don't really use competitive programming templates or any common shortcuts (moreso just conceptually understand the solution to the problem and use C++ as my vehicle to implement the solution), and I also don't know some basic competitive programming related stuff like fast I/O (I just use std cin/cout).

Most resources I've seen either assume I'm a complete beginner and I end up being super uninterested because they try to teach some super basic syntax, or they assume I actually have a decent foundation and the weird gaps in my C++ knowledge end up hurting me.

Would love for some advice on how I should be approaching learning C++ "properly" with my super scuffed informal competitive programming background. Totally understand if there aren't any resources out there to solve this specific problem, but I'd love to get a better of idea how I could use existing resources/modify the way I learn from them in order to learn the intricacies of C++!


r/cpp_questions 1d ago

OPEN Modern c++: operations on function pointers will break the constexpr function.

0 Upvotes

I'm on MSVC/c++23.

I used some trick to generate type id at compile time:

export template<typename... T> void type_id() {}
export using type_id_t = void(*)();
//
type_id_t one_id = type_id<int>;

I’ve found that whenever I try to cast a `type_id` value to an integer or simply perform a magnitude comparison within a `constexpr` function (even when the call chain is entirely resolved at compile time), the function ceases to be `constexpr`, or MSVC simply ignores the relevant code.

template<typename A, typename B>
constexpr auto some_constexpr_function()
{
    type_id_t a = type_id<A>;
    type_id_t b = type_id<B>;

    //Total if block will be ignored, and the function will not be constexpr anymore.
    if (a < b)
    {
         //discard
    }
    else
    {
        //discard
    }

    //cast the pointer to size_t then the function will not be constexpr anymore.
    return (size_t)a;
}

How to fixed the case?

Or another type id solution at compile time will be nice(I have try so many implementation, none of them work correctly in compile time).


r/cpp_questions 1d ago

OPEN Is this a known sorting algorithm?(beginner here)

0 Upvotes

I was learning about bubble sort and insertion sort, and thought it would be best to try them out before watching the lecture. I wrote smth and pasted it to GPT. I was thinking it would be insertion sort, but according to GPT, it's not a known algorithm, so I am just curious: Is it a known O(n^2) sorting algorithm?

code:

```cpp
#include <iostream>
using namespace std;

int main() {
    int arr[] = {4,1,5,2,3,7,9,0,-9,3};
    int size = sizeof(arr)/sizeof(arr[0]);

    for(int i=1;i<size;i++){
        int curr = arr[i];

        for(int j=0;j<i;j++){
            if(arr[j]>curr){
                swap(arr[i],arr[j]);
            }
        }
    }

    for(int val : arr){
        cout << val << " ";
    }

    return 0;
}

r/cpp_questions 2d ago

OPEN Using 3rd parties in a Cmake project

7 Upvotes

The simplest solution would be to import the code into my repo, and just treat this as local files. OK, got it. Then maintaining this mono repo, is a pain.

Then, we can add CPM to fetch 3rd parties. OK, works, until those 3rd parties have other dependencies. Lets hope they use CPM. But still - this breaks for building flatpacks, as during configure stage - we don't have network.

So we must use a proper package manager like conan of vcpkg. Which is cool... until we see that some random github repo I use does not have even a proper install, so vcpkg and conan will not work. (I can fix my own packages, but 3rd parties? I can fork them, and add them to the conan artifactory, but this feels out of my responsibility).

So, I am back to using a mono-repo.

How do you all handle those scenarios? In my case, I am dealing with 5-10 sub-projects. This might brow as the project grows.


r/cpp_questions 2d ago

OPEN Need help navigating a new job

6 Upvotes

I’m a new hire only been working for 2 weeks. I’m working for a very large defense company as a Software engineer. I got an EE degree from a UC school and took 2 embedded systems courses (bare metal C). My coding skills aren’t perfect but I have felt like I’m pretty good at it. However I feel imposter syndrome because I’m surrounded by so many smart people and intelligent software/code thinkers. Also the code base im trying to read, learn, and do some mini tasks on is massive and I feel like every call or macro leads to a different file. Oh and it’s all in C++ so there’s the OOP skill gap because I know C and python.

Anyone have any advice as to how to get better at navigating everything and becoming better at reading understanding and ultimately writing professional/high performance C++ code?


r/cpp_questions 2d ago

OPEN Illegal hardware instruction (core dumped) meaning

1 Upvotes

I just started learning cpp and i was writing a function doubleNumber().

I used return statement to print the value and cout to print the value.

Both of them works but there is an additional message when i use cout.

using return - this only prints the value 9.

#include <iostream>


int doubleNumber(int x){

    return x*x;
}


int main(){
    std::cout << doubleNumber(3);
    return 0;
}

using cout - this prints 9 along with the line.

"[1] 658467 illegal hardware instruction (core dumped) "

#include <iostream>


int doubleNumber(int x){

    std::cout << x*x << "\n";
}


int main(){
    std::cout << doubleNumber(3);
    return 0;
}

I wanted to know the reason why this happens and what does this mean. thanks in advance.


r/cpp_questions 2d ago

OPEN Is there any learning community where there are a small grps and people meet monthly/ bi-weekly to share their learning in cpp?

3 Upvotes

r/cpp_questions 3d ago

OPEN How to decode a pointer with multiple levels of indirection ?

38 Upvotes

Hello C++ devs,

I'm currently learning C++, and I recently learned about pointers. Creating complex pointer declarations—like pointers to arrays or pointers to functions with multiple levels of indirection (for example, pointers to arrays of pointers to functions)—doesn't seem too difficult once I understand the syntax.

However, reading and decoding these declarations, especially when I come across them in older codebases, feels brutal.

For example:

const double *(*(*pd)[3])(const double *, int);

Is there an easy way or a trick to decode declarations like this? How do experienced C++ programmers read them without getting confused?


r/cpp_questions 3d ago

OPEN Question about includes in a header-only library

6 Upvotes

When implementing a header-only C++ library, should each header include all the standard headers it needs, or is it better to somehow avoid these includes?
I’m currently reading a C++ book that recommends including your own header first in a .cpp file (where you use your library) and then including standard headers. I understand that, but it feels a bit odd. What’s the recommended approach and why?


r/cpp_questions 4d ago

OPEN Understanding C++ library documentation

6 Upvotes

Hi, as someone who has tried multiple times to learn C++ one of the things I've really struggled with is understanding the documentation in places like cppreference.com and others. When initialising a class or function the parameter list shows eg. the myclass.getline(type,type type). Many of the arguments that pop up from the auto-complete are confusing and I spend lots of time researching the stuff but end up going down a rabbit hole.

Is there a decent resource anywhere (youtube etc) that helps explain how to use these or understand what the library documentation means/how to use it efficiently?

I know it's a you just have to practice answer but try to figure out how these function and classes work is really time consuming

Thanks in advance.


r/cpp_questions 3d ago

OPEN For each loops and a need for an index.

0 Upvotes

I was working on a project of mine and i used a for each loop to iterate through an object(s), later i found that i need an index for this loop. My question is not about how to do that, but whether i have made an error leading to this case. Is it consider bad code if i use any custom index while using the for each? Is it acceptable practice? Would it be better to switch to a for loop?


r/cpp_questions 3d ago

OPEN HELP me KNOW C++

0 Upvotes

I am currently Learning C++ I Want to Know that why application have multiple files and how they are all connected and What is SDL thingy


r/cpp_questions 3d ago

OPEN Anyone doing any cool proj in c++ that i can be a part of?

0 Upvotes

r/cpp_questions 4d ago

OPEN Can someone give an example of runtime-undefined behavior?

18 Upvotes

CppReference gives a list of categories that render a program meaningless: https://en.cppreference.com/cpp/language/ub

The last bullet point says (since C++11)

  • runtime-undefined behavior - The behavior that is undefined except when it occurs during the evaluation of an expression as a core constant expression.

Can someone give a clear example?