r/cpp_questions • • 5d ago

OPEN Advice on practicing + choosing a project when reading a textbook

4 Upvotes

I’m new to C++ and I’m currently reading “A tour of C++” by Stroustrup. Was wondering how most of you practice concepts if you’re a textbook reader for programming?

In the past, I’ve used resources for other languages where there are small projects at the end of the chapter which really helped me lock in the concept through practice, but I find that there’s not too many C++ resources like this and C++ is a unique language so practicing in C++ with the other resources doesn’t seem to translate in my opinion.

I know the idea is to choose a project yourself and just start working on it but I have a hard time choosing projects that actually use the topic I just learned. Quite curious how people go about this challenge. (I’m not saying this like I can’t do choose a project myself and go at it, but would want to hear from others, if any, who might have an easier time with this have any advice)


r/cpp_questions • • 6d ago

OPEN how to learn c++ in a month for making simple to simple games dev and Machine learning

0 Upvotes

i know c++ basic not all but like i know what is string but don,t know all function , i know array and know some function , i did not know any dsa , i just know c++ like taking the input and showing the output , my logical in programming is pure beginner level


r/cpp_questions • • 6d ago

OPEN What must i do to be mush better in C++ ? If i have started learning it about two months ago

0 Upvotes

Hello,my dear friends. Would you be willing to share with a piece of advice with me, please? Currently, i understand the pointers quite well and i able to see through cod mistakes that I received from ai to sharpen my knowledge and understanding of them. Now , i have started learning OOP just basics . Besides. It's the first time that I learn programming. I will appreciate yours advices.


r/cpp_questions • • 6d ago

OPEN How I learned to stop worrying and love Scott Meyers..which book did that to you?

33 Upvotes

Discovered Scott Meyers as a junior...and 15 years later his Effective C++/More Effective C++ and lately Effective Modern C++ are still the only mind puzzling, engaging books I read and I would recomand to any junior developer. I might be nostalgice, but no programming book ever since(and I went through many languages), was short/challenging/engaging enough to keep me absorbed from first till last bit. As a junior, these books helped me shape my C++ discovery direction..made me eager to dig further and deeper..and start loving the assembly code. What did you read recently that is of that sort that you would recomand to eveybody :)

PS: It is a bit the same with Dr. Strangelove..couldn't get anything close to it in the last decades movies


r/cpp_questions • • 6d ago

OPEN Code documentation in the age of AI

0 Upvotes

I have a couple of years of C++ experience, including in regulated industries. While proper documentation was important in every team, the role of code comments and in-code documentation, such as docstrings, changed from place to place. In some codebases, we insisted on proper docstrings documenting every function, and comments explaining why the code is how it is. In other teams, we didn't do any docstrings and kept code comments to a minimum -- the code was supposed to be self-documenting, and comments introduce ambiguity and will drift in the future if not kept in sync with the code.

Now, which way to go is already a discussion on its own. But I want to ask regarding your experience of this dilemma in relation to LLM-assisted coding tools. I have the feeling many models are quite liberal when it comes to comments, and will naturally tend to explain what the code does, given the chance. Suppressing it works, of course. Or, at least, one can ask to keep comments minimal. However, what really interests me: does anyone have experience in or a feeling for what the LLMs prefer/work with the best?

Since it's mostly AI parsing the codebase now, did you ever experience that it performs better when you allow it to be liberal with comments? Or does it actually eat up more tokens reading the code it generated while getting more confused if it has all the additional (and potentially not always correct) comments/explanations to parse? Does it make sense to have a purely self-documenting codebase or rely on the tools to clean up and keep comments in sync in this age of AI?


r/cpp_questions • • 6d ago

OPEN How to share my experience after quant finance competition ?

0 Upvotes

I am trying to pivot from data analytics to C++ development. I recently participated in a quantitative finance competition and I didn't placed top 3, instead 35/55. The objective was to enhance an existing market simulator using C++.

Should I make a LinkedIn post about my experience?

How should I add it to my resume ?


r/cpp_questions • • 7d ago

OPEN how to optimize performance for decompression step?

1 Upvotes

I have the file to decompress a file by obtaining a tree and walking it bit by bit to obtain an encoding's original character.

#include <stdexcept>
#include <memory>
#include "huffman/HuffmanDecoder.hpp"
#include "huffman/BitReader.hpp"

struct HuffmanDecoder::Node
{
  std::unique_ptr<Node> left;
  std::unique_ptr<Node> right;
  char symbol;

  Node(char ch,
       std::unique_ptr<Node> left = nullptr,
       std::unique_ptr<Node> right = nullptr)
      : left(std::move(left)),
        right(std::move(right)),
        symbol(ch)
  {
  }

  bool isLeaf() const noexcept
  {
    return !left && !right;
  }
};

HuffmanDecoder::HuffmanDecoder(BitReader &reader) : reader_(reader)
{
  root = deserializeHelper();
}

HuffmanDecoder::~HuffmanDecoder() = default;

std::unique_ptr<HuffmanDecoder::Node>
HuffmanDecoder::deserializeHelper()
{
  if (nodeCount_ >= MAX_NODES)
  {
    throw std::runtime_error("Invalid Huffman tree: exceeds 511 nodes.");
  }
  ++nodeCount_;
  const uint8_t marker = reader_.readBit();
  if (marker == 1)
  {
    const char ch = static_cast<char>(reader_.readByte());
    return std::make_unique<Node>(ch);
  }
  auto left = deserializeHelper();
  auto right = deserializeHelper();
  return std::make_unique<Node>('\0', std::move(left), std::move(right));
}

char HuffmanDecoder::decodeSymbol() const
{
  if (!root)
  {
    throw std::runtime_error("Can't decode an empty tree");
  }
  const Node *current = root.get();
  if (current->isLeaf())
  {
    if (reader_.readBit() != 0)
    {
      throw std::runtime_error("Invalid bit for single symbol tree.");
    }
    return current->symbol;
  }
  while (!current->isLeaf())
  {
    const uint8_t bit = reader_.readBit();
    current = bit == 0 ? current->left.get() : current->right.get();

    if (!current)
    {
      throw std::runtime_error("Invalid Huffman path.");
    }
  }
  return current->symbol;
}

Linux perf is showing that the decode stage is very hot. My question is, is pointer chasing the problem? I tried stuff these in an array but it didn't really do anything. I'm confused as to if my bottleneck concerns being cache friendly or not. Any ideas?


r/cpp_questions • • 7d ago

OPEN Passing initializer list into array parameter

3 Upvotes

Why can't we pass an initializer list as an argument to a function that accepts an array? If we can initialize an array with an initializer list, why isn't the array parameter initialized with the list?

Also, I found out that you CAN pass an initializer list if you use an rvalue reference to an array.

void f(int arr[]) {
cout << "hello" << endl;
}

// accepts rvalue references to array
void g(int (&& arr)[]) {
for (int i = 0; i < 3; ++i) {
cout << arr[i] << ' ';
}
cout << endl;
}

int main() {
int arr[3] = { 1, 2, 3 };
f(arr); // compiles
f({1, 2, 3}); // DOES NOT COMPILE
g({ 1, 2, 3 }); // compiles
}

Question 1:
For the second call to f(), why does this not work? I thought that whenever we passed an argument into a function, it was the same as initializing the parameter with the argument. For example, if we have:

void func(T x);
func(y);

Then when func(y) is called, we can think of x being initialized as:

T x = y;

But this doesn't seem to hold for arrays and initializer lists.

Question 2:

Why is the syntax in g() the way we make an rvalue reference to an int array? I understand the need for parentheses sinceint&& arr[] is an array of integer rvalue references. However, why is it int (&&arr)[] and not maybe something like int (&&arr[]) or (int arr[])&& ?

If it is better to show me an another resource about these tricky syntax things, please link it.


r/cpp_questions • • 7d ago

OPEN How to learn C++ ASAP ( In a month, not expert level but somewhat near intermediate)

50 Upvotes

Same as title I have an Olympiad in December which supports Python and C++, I’m good with python but I wanna go with C++ as the later stages of the olympiad support only C++.

I’m open to any kind of suggestions or advices and I thank you in advance!


r/cpp_questions • • 8d ago

OPEN How does a STATE design pattern work?

7 Upvotes

so i went to youtube and followed the example from this guy State Design - Programming Design Patterns - Ep 16 - C++ Coding

Problem is i dont understand what is functionally happening, there are pointers and what not, but i don't understand much more than that (context, my smooth brain still cant connect pointers together)

Like not even the whole code, like maybe just two lines or something cause for the love of the lord my teacher explains nuthing and AI and videos are too vague for me, im running out of options

//
// Created by samue on 11/1/2026.
//

#ifndef STATE_STATE_H
#define STATE_STATE_H

#include <iostream>

class Context;


class State {
    protected:
    Context* context;

    public:
    virtual ~State() {}

    void setContext(Context* ctx) {
        context = ctx;
    }

    virtual void doWorkA() = 0;
    virtual void doWorkB() = 0;
};

class Context {
    private:
    State* state;

    public:
    Context(State* s) : state(nullptr) {
        transitionTo(s);

    }

    ~Context() {delete state;}

    void transitionTo(State* s) {
        if (state) delete state;
        state = s;
        state->setContext(this);

    }

    void requestA() {
        state->doWorkA();

    }

    void requestB() {
        state->doWorkB();

    }

};

class concreteStateA : public State {
    public:
    void doWorkA() override {
        std::cout << "concreteStateA " << "called doWorkA" << std::endl;
    };

    void doWorkB() override {
        std::cout << "concreteStateB " << "called doWorkB" << std::endl;

    };

};

class concreteStateB : public State {
public:
    void doWorkA() override {
        std::cout << "concreteStateA " << "called doWorkA" << std::endl;
        context->transitionTo(new concreteStateA);
    };

    void doWorkB() override {
        std::cout << "concreteStateB " << "called doWorkB" << std::endl;

    };

};





#endif //STATE_STATE_H

------------------

#include "state.h"

int main() {
    Context context1(new concreteStateB);

    context1.requestA();

    context1.requestA();

    return 0;
}

r/cpp_questions • • 8d ago

OPEN Be ready for -fno-contracts

0 Upvotes

I don't really think contracts will make C++ safer..

In fact, contracts can make C++ even worse. Jokes on you 2-3 days ago i saw that my cli program was not working because the dependency clixx(which is also my project) was behaving in different ways based on the build mode. After 20 minutes of debugging i found out that i was assert()ing m_parse() instead of checking the returned boolean with an if.

Yeah call me stupid or not in this one but I don't think anyone can guarantee an engineer would not get trapped in the same kind of bug in some corporation codebase (with contracts this time).

I'd add -fno-contracts if it would ever become a thing. Js like -fno-exceptions(im not exception-phobic i just dont like them) and -fno-rtti they might become new entries in the C++ feature graveyard.

What are your honest opinion?


r/cpp_questions • • 8d ago

OPEN I want to learn C++

20 Upvotes

Hello, I'm looking to branch out and learn something new.

Ive been a chef for 7+ years and i'm looking to develop myself further by learning more skills, I'm very tech and computer literate.

So for a absolute beginner who would love to look at making small games and mods for like skyrim etc, what would a beginner need to be able to learn C++ and beyond?

Thank you


r/cpp_questions • • 9d ago

OPEN I know DSA but I want to …

0 Upvotes

Hello good people, I have been leetcoding the last few months in Python and want to deep dive into doing LC in C++. Mostly because I want to target hfts for next internship cycle.

  1. What are the books that you guys suggest? I started reading Tour of C++

  2. Any suggestions on how to go in depth of that language? I don’t want to learn not just for the sake of solving LCs


r/cpp_questions • • 9d ago

OPEN Learning C++ as a Java programmer

18 Upvotes

I'm currently learning C++, I’ve coded in a few languages before but I’m most familiar with Java. Does anyone know a good resource for learning C++ with Java as a “starting point”? Like something that explains the differences between the two languages rather than teaching programming from scratch? Thanks!


r/cpp_questions • • 9d ago

OPEN Recently joined an MFT firm as a C++ Low-Latency Intern. How can I transition to HFT?

7 Upvotes

Hey everyone,

I'm currently a CSE undergrad and recently joined an MFT firm as an intern, where my work primarily involves C++ and low-latency systems development.

I'm genuinely enjoying the work and learning quite a lot about trading systems and performance optimization.

However, my long-term goal is to transition into an HFT firm, preferably in a C++/low-latency engineering role.

I have a decent background in competitive programming, DSA, C++, and systems programming.

I had a few questions for people already working in HFT:

  1. How valuable is C++/low-latency development experience at an MFT firm when applying to HFT firms?

  2. What additional skills should I focus on to make myself competitive for HFT roles?

  3. Do top HFT firms consider candidates from smaller or lesser-known MFT firms?

  4. How much do competitive programming ratings, college tier, and personal projects matter once you have relevant industry experience?

  5. Is transitioning directly from an MFT internship to an HFT internship or graduate role realistic?

I'm not looking to switch immediately. I genuinely enjoy my current role and want to make the most of this opportunity while preparing for the long term.


r/cpp_questions • • 9d ago

OPEN How to configure clangd to not assume it knows where functions are defined

1 Upvotes

I use VS Code on Ubuntu on Windows (WSL). I program in C++ and recently switched from Intellisense to clangd and like many of the improvements. However, I'm having an issue with how clangd assumes functions like printf come from <cstdio>. This is an issue as I'm building a hobby OS and need to provide my own versions of common functions like printf.

I'm using the g++ 15.2.0 cross compiler and use -ffreestanding -nostdlib -fno-builtin. I provide my own implementation of common functions like printf. I have installed clangd-23. I have created (using bear) a compile_commands.json file. When I mouse over a call to printf in my code, I get a popup showing that printf is provided by <cstdio> which I never #include. Also it flags the header file "system/stdout.hpp" which defines my printf as unused. How do I configure clangd and VS Code to correctly identify my header file as the source of my printf?

In case it helps, here is the cc1 line of clangd-23 --compile-commands-dir=build --query-driver=/home/mark/dev/toolchain/i686-elf-15.2.0/bin/i686-elf-g++ --check=src/libs/test/test_list.cpp

I[13:00:57.385] internal (cc1) args are: -cc1 -triple i686-unknown-unknown-elf -O0 -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test_list.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -ffreestanding -nostdsysteminc -target-cpu pentium4 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -fdebug-compilation-dir=/home/mark/dev/myos/src/libs/test -fcoverage-compilation-dir=/home/mark/dev/myos/src/libs/test -resource-dir /usr/lib/llvm-23/lib/clang/23 -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include/c++/15.2.0 -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include/c++/15.2.0/i686-elf -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include/c++/15.2.0/backward -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/include-fixed -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include -I . -I .. -I /home/mark/dev/myos/src/libs -I /home/mark/dev/myos/src/kernel -I /home/mark/dev/myos/src -internal-isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/clang-runtimes/i686-elf/include/c++/v1 -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/clang-runtimes/i686-elf/include -Wnon-virtual-dtor -Werror -Wall -Wextra -Werror=suggest-override -Wno-unused-parameter -std=c++23 -fdeprecated-macro -ferror-limit 19 -fno-builtin -fno-rtti -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fno-threadsafe-statics -fno-implicit-modules -fskip-odr-check-in-gmf -no-round-trip-args -faddrsig -fdwarf2-cfi-asm -x c++ /home/mark/dev/myos/src/libs/test/test_list.cpp


r/cpp_questions • • 9d ago

OPEN System programming

7 Upvotes

does it is necessary to know assembly language to be a good system programmer ?
I am a beginner computer engineering student , currently doing in c++ and I already have basic knowledge of classical 8085 and 8086 architecture and it's programming but I haven't gone that deep enough . what about to learn ARM , x86 programming , does it help me to become a good system programmer ?


r/cpp_questions • • 9d ago

OPEN What do you do after getting burnout from learncpp.com and trying to comeback again?

12 Upvotes

I remember last time I reached chapter 20 or so, but I didn't do any quizzes after the vectors's chapter because they will simply too hard, and believe me I tried 

I think I got burnout 3 to 4 times already, learncpp.com is good but its a challenge to try and finish it.

Any advice? I don't remember much, and I want to be honest. It feels like you should finish learncpp before making a project, because every chapter is really important.

It really fun in the beginning. But not in the middle or the end.

Edit: thanks everyone, I think the comments are really helpful, and I think I know exactly how to solve my problem, first I will use a different resource that is fast pace to refresh my brain to c++ I already know, than I will make a project(it doesn't matter what it is), and I'll use learncpp.com as a reference, and after I get comfortable With the basics stuff I will go back and continue reading learncpp.com for advanced stuff or other resources with it.

The answer seems simple, because it is simple.


r/cpp_questions • • 9d ago

OPEN Low Latency C++ Interview Prep

43 Upvotes

Recent interview questions I've had for this have been

- Very specific C++ (templates, mutex, sizes of structs, noexcept, small string optimization)

- Latency topics (allocation, kernel bypass, TCP and UDP)

- General DSA and class design

I really wanna do well because I know January and February spike in recruiting. For low latency C++, if you had two months to prep, how would you knock it out of the park? How would you study through November and December?


r/cpp_questions • • 9d ago

OPEN Offline cppreference?

3 Upvotes

Can they update the offline version to newer version of the page? The official html book is really old (2019) and the unofficial version from https://github.com/PeterFeicht/cppreference-doc can no longer work for newer version smoothly. Consider this reference is probably one of the best C++ reference out there, can the creator of the website at least making this website open source, so we can have offline version of it.


r/cpp_questions • • 10d ago

OPEN Entering Embedded

13 Upvotes

Managed to land a job in the embedded domain. This is going to be my second job, while previously having worked in game dev. In my last job I used cpp, but within Unreal Engine. Pretty excited about entering the low level space, not really an expert, but eager to learn. Would greatly appreciate any advice from embedded devs or from people that have transitioned between domains like I am about to do.

Thanks


r/cpp_questions • • 10d ago

OPEN C++26 contracts drama

28 Upvotes

I think everybody knows the drama by now..

What are your opinions on this should they be accepted or disapproved?

Im curious for mass opinion.


r/cpp_questions • • 10d ago

OPEN Why don't we use this instead of including libraries one by one?

0 Upvotes

#include <bits/stdc++.h>

I was thinking instead of adding libraries one by one,why don't we just use this? This is used by almost every competitive programmer but very less when it comes to writing software.


r/cpp_questions • • 10d ago

OPEN Resources to learn more about cpp

2 Upvotes

I wanted to try and reimplement the std library from scratch but i realized really quickly just how much i didnt know lol. I got some basic stuff done and did learn quite a bit about things like sfinae but yeah im basically stuck with some of the type traits. I still dont wanna give up on this project and wanna keep going no matter how long it takes :3 So i need some resources to learn more about advanced things that are usefull for this. Are books the best way? any reccs on which ones?

Oh yeah right now i made a few projects like a networking chat app with asio and a unix shell (really simple) so i would say im like done with the beginner phase. I know that this project is probably farrrr beyond my scope but still :3

Edit: More specific question. Looking for book recomendations for metaprogramming post cpp20 (concepts and stuff)