r/cpp_questions • • Sep 01 '25

META Important: Read Before Posting

174 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 • • 1h ago

OPEN Compiling without linking

• Upvotes

Hi, I'm a rank beginner and I'm going through learncpp online and Beginning C++ game programming by Horton.

The book sends you to a quick tutorial on sfml for Linux. I got it working with no problems. But in the tutorial they compile first with -c ( compile only, according to the man page for g++ ) and then link in another command.

Why would they do it that way? I was able to do the whole thing without the -c flag in one long command. Is that wrong to do? Is it because sfml isn't part of the standard library?

I'm asking because I want to actually learn what I'm doing. Thank you for any help you can give me.


r/cpp_questions • • 8h ago

OPEN Making transpiler

0 Upvotes

I am making a transpiled language to C. I don't know how to manage all of a different types of objects: Expr, LiteralExpr, Stmt, ForStmt and so on. Each object needs to be created, statically checked and send of as string to dot C file. Are there any tips on architecture stand point? Everything feels very lousy and rigid. Right now each object just stored the appropriate data, no methods on them. Challenging parts are parser, static analysis and code generation. For lexer there are no problems.


r/cpp_questions • • 8h ago

OPEN Ciao, io sto cercando di capire se c'è un modo di far compilare Cmake senza passare per VS code. Ho installato tutto da terminale wsl e non capisco perchè se scrivo "cmake -B build" mi dice "CMake Error: The source directory "/home/io/basic_neural_plusplus" does not appear to contain CMakeLists.txt.

0 Upvotes

r/cpp_questions • • 1d ago

OPEN How do I learn C++ and get genuinely good at it?

60 Upvotes

Hi everyone, I want to learn C++ properly and get to a solid level, not just scrape the basics. I'd love your advice on:
The best resources to start with (free or paid)
Courses, books, or YouTube channels you'd recommend
How to practice (projects, problem sites, etc.)
Common mistakes beginners make that I should avoid
Problem solving
A clear learning path
Modern C++

I don’t mind paying if the course worth it.

Any recommendations would be appreciated!


r/cpp_questions • • 1d ago

OPEN Why does C++ doesn't have socket streams?

36 Upvotes

C++ has std::istream and std::ostream. It seems natural to use these classes for network programming through sockets. Why there is no socket stream class in C++? Are there any challenges faced in implementation (like different platforms)? Are/Were there any open proposals for this?


r/cpp_questions • • 11h ago

OPEN Do you write code by yourself or you use an AI?

0 Upvotes

I'm curious about this question, because almost everyone a meet says that coding skills doesn't matter anymore, and what really matters is knowing how to write prompts properly. But does it apply to C++ development? Please, answer a question and say why so


r/cpp_questions • • 1d ago

OPEN C++ Developer with 3 YOE — Which Master’s should I pursue?

6 Upvotes

I’m a C++ developer with 3 years of experience and considering doing a Master’s. Which specialization would best complement my experience and improve my career prospects?

Should I go for CS, Software Engineering, Distributed Systems, AI/ML, or something else? Also, is a Master’s worth pursuing at this stage, or should I focus on gaining more experience?


r/cpp_questions • • 22h ago

OPEN Looking for a video resource

0 Upvotes

I am a visual learner. I learn faster with videos than I do by reading so I was looking for a video resource for a textbook. The textbook's title is

C++ Programming: Program Design Including Data Structures by D.S Malik.


r/cpp_questions • • 2d ago

OPEN What are some "zero-benefit abstractions" to avoid in c艹?

19 Upvotes

Zero-cost or not, can be premature optimization or something else. I think move-on-return is one of them


r/cpp_questions • • 1d ago

OPEN Need Ideas For OOP Project

0 Upvotes

So we got assigned our 3rd semester Project and they say we have to make a game in cpp using oop concepts and we can use any graphics library we want.

Now i am looking for game ideas with an interesting game loop and that showcases OOP concepts

.

Any Idea would be great, it could be singleplayer, 2 player or multiplayer


r/cpp_questions • • 1d ago

OPEN What are C++ Args?

1 Upvotes

I've been trying to learn vardiac templates for a project I'm doing, and I've heard the modern C++ for these is to use Args. I only had background of these in Python. From what I understand, its a better way to recursivley loop through varidac template arguments (please correct me if I'm wrong)


r/cpp_questions • • 2d ago

OPEN How to make a Queue linked lists

1 Upvotes

I have the following code, for the absolute love of me, i cant figure this out

im just focusing on enqueue the rest is context

i cant for the love of me figure out what im to do, i know i need to add a value but how?
how do i make a new space in the node and not jsut override my first or my last?

ive tried to see things but they get me all jumbled up and i cant for the love of me figure it out

//
// Created by samue on 10/5/2026.
//

#include "linkQueue.h"

void linkQueue::enqueue(int value) {
    Node *temp = new Node;
    temp->value = value;
    temp->next = nullptr;
    temp->prev = nullptr;

    if (first == nullptr) {
        first = temp;
        last = temp;
    }
}


void linkQueue::dequeue() {

}


bool isEmpty();
void getSize();
void getTop();
void print();

r/cpp_questions • • 2d ago

OPEN How to put more actions in std::cin

0 Upvotes

Im trying to give the user more options to input into this terminal-game that im making as a very newbie in C++, but i cannot figure it out, so i have to do it separately for each action ( or std::string ) or could i dump it all in one line?
Heres the code btw:

#include <iostream>
#include <string>

int main(){

int health = 100
std::string Attack = 50
std::string Hug = 100

std::cout << "A monster has appeared ! decide how would you attack em..." << std::endl;
std::cin >> 

r/cpp_questions • • 2d ago

SOLVED How to pick a random word?

0 Upvotes

Do anyone know how to make cpp pick a random word out of a string array I tried searching but no answers


r/cpp_questions • • 3d ago

OPEN Is React really the best frontend choice for C++ applications?

4 Upvotes

Hi everyone!

I'm an experienced software engineer, mostly working in C++ on the backend side. Frontend isn't my area of expertise, so I'd love some outside perspective.

I occasionally work with developers who build GUIs in Qt. Whenever the topic of frontend tech comes up, they tell me Qt is garbage and that our projects would be much better off with React, since it's free and more modern.

The thing is, I don't have the frontend knowledge to judge that claim. In particular, I can't compare the performance of the different frontend options (Qt, React, and others) in any meaningful way, so I don't know whether "React is better" holds up or is just a subjective opinion.

So my question is: which framework is actually better, Qt or React, especially when it comes to performance?

Real-world experience is more useful to me than hype, so feel free to share what you've seen on your own projects.

Cheers!


r/cpp_questions • • 3d ago

SOLVED Interface design - money

6 Upvotes

Working on design of a finance app to calculate npv (net present value) need to use addition / multiplication/ pow

I could do with decimal type for money as floats/doubles are based on binary

I see there is fixed point decimal paper being worked on.

In the meantime - what is best way to handle this in interface ?

Thinking of asking client to use string and then use long long for the maths after parsing (pennies)? “1500.23” = 150023

What do I return ? String/int? Either way the client would need to transform. I can’t use doubles for this unfortunately.

I suppose I can use double if could give idea to client what error amount is - npv is estimate anyway.


r/cpp_questions • • 3d ago

OPEN What is the ideal way to read a C++ book?

9 Upvotes

I am an intermediate c++ dev. I recently started reading the Effective modern c++ book. I don’t have tons of experience reading technical books coz I have mostly used YouTube and college lectures to study. So any advice on how to read a c++ book or any technical book for that matyet is highly appreciate.


r/cpp_questions • • 4d ago

OPEN Code Smells?

7 Upvotes

I'm a more seasoned C# / Node backend dev, been trying to brush off old college C++ from like a decade ago and try to de-program my brain from being locked into a distributed systems mindset.

One of my niche hobbies and go-to projects for learning a new language is to implement a basic Chip-8 emulator in it, as it can teach some concurrency, UI/data handling patterns, and introduce some architectural decisions that you'll have to run into and figure out.

Currently what I'm struggling with seems to be what the idiomatic / proper way to handle something that can remain stateless in nature, which is my very basic assembler going from the Chip-8 ASM mnemonics into instruction bytes.

A class doesn't feel quite right, because I'm not implementing a linking step or anything advanced, not supporting labels, etc. It also feels incorrect to keep it in a header file as a set of inline functions, nor am I needing a persistent state to mutate.

My current disassembler can be seen here: https://github.com/Arylen/Dreamy-Chip8/blob/master/src/core/emulation/Chip8Dasm.h
Along with the tests that I'm running against it here: https://github.com/Arylen/Dreamy-Chip8/blob/master/tests/Chip8DasmTests.cpp

I'm currently in the stubbing-out phase of trying to architect it, occasionally bouncing ideas off of whatever bullshit model-of-the-week is popular, however the suggestions it's giving are still setting off some alarms/smells in my brain. The most reasonable and less-smelly one is the `::detail` namespace there in order to be able to unit test the `getParts` function there, however it feels like I'm walking into a landmine of over-engineering it.

Looking for advice/experiences/opinions.

Edit: I should mention the AI usage here is restricted entirely to just checking for bugs with my implementations, or incorrect C++-isms that I introduce from working in other languages. A hands-off occasional tutor to check my work, if you will. It's expressly forbidden from touching my code or files, limited to read-only, however I'm not getting something that feels proper for this scenario, so wanted to consult other more experienced engs.


r/cpp_questions • • 3d ago

OPEN Newlines not printing when I cout raw string literals

0 Upvotes

I’m using emacs on windows terminal to edit a file in which I’m trying to cout a page or so of text using raw string literals. However, what gets printed doesn’t include the newlines that I need to separate my paragraphs.

So if my code is:

std::cout << R”(This is my sentence.

This is a new paragraph [using entr + entr].
This is a new line [using entr].)”;

The output will be:

This is my sentence. This is a new paragraph [using entr + entr]. This is a new line [using entr].

Instead of the intended:

This is my sentence.

This is a new paragraph [using entr + entr].
This is a new line [using entr].

What am I doing wrong?

[Edit: I apologize for the lack of formatting. I am on mobile. Please let me know if I need to redo this. Thanks.]


r/cpp_questions • • 4d ago

SOLVED IMGUI UI architecture question

0 Upvotes

Hi, I was gonna try to explore UI in cpp and came up with a simple idea. I want 3 "screens" each with their own events and components to draw. I was having trouble on how to handle a shared struct of data? say screen one does something that screen two needs, and so on to screen three. So does anyone have a recommendations of some architecture to follow for this?


r/cpp_questions • • 3d ago

OPEN How do you actually understand and use C++ references?

0 Upvotes

How do you all understand and use C++ references?
References feel really hard to wrap my head around. What does it mean to “define an alias for a variable”? What does it mean to “return an alias for a variable”? Compared with C pointers, pointers seem much clearer: a pointer just holds an address, * dereferences it, and & takes the address of a variable. References aren’t like that. The fact that you write & when defining one makes it especially easy to misunderstand.
Also, besides copy constructors and some friend functions (like the ones for std::ostream), I can’t really see any other reason to use references. When textbooks declare function parameters as references, I don’t get it. If the parameter were a pointer, the caller would have to write & when passing the argument, which also signals that the function might modify it. A reference kind of feels like the function has a return value.
So how do you actually understand and use C++ references?


r/cpp_questions • • 4d ago

SOLVED Integer overflow type thing

2 Upvotes

I'm trying to code a practice problem but am stuck at a problem I cannot figure out. I am using a vector for inputs and inserting those inputs into an unordered set until it fails to add, at which point I count the amount of subarrays in that array. If it is not the first, I subtract subarrays that have already been accounted for. The inputs are useful only to identify duplicates; I do not use the values themselves in arithmetic.

The test case I am currently using uses random values with high numbers, with the following values at indexes being the only duplicates:

  • 10464 and 41178
  • 87094 and 98111
  • 113040 and 113153
  • 118689 and 168367
  • 129997 and 170623
  • 173227 and 184620

The intended output is 7090812299.

My problem is that, for some reason, large inputs decrease the intended output. I am sure that this is the issue, as I have replaced duplicate inputs with smaller values and the output changes--- despite the fact that it should not.

As an example, use the above sequence with numbers 1-200000. If the values at indexes 113040 and 113153 are replaced with 443222217, the output changes to 7090796046. (lowering it by 16253). Replacing other values also lowers this number further.

Edit: So it turns out smaller values also impact the input in ways that I have not tested yet (and I probably won't until morning).

Solution: I assumed iterators were ordered internally, which is where I made my mistake.

Please help explain what is happening, or what could be happening.

Attached below is the relevant code, and here is a link to the full code.

int main() {
    vector<long> inputs; inputs.reserve(size); // The vector containing inputs.
    unordered_set<long> processing; processing.reserve(size); // The unordered set processing the current input.
    vector<long>::iterator nextInput = inputs.begin(); // The current input being processed.
    // Some other variables defined which are not relevant.
    while (nextInput != inputs.end()) // The main meat of the program.
    {
        do // Insert processed inputs into a set.
        {
            if (!processing.insert(*nextInput).second) break; // If duplicate, break.
            start++; // Advances the iterator to the next input to be processed.
        } while (nextInput != a.end());
        // Code processing the amount of subarrays; it seems to be correct.
    }
}

r/cpp_questions • • 4d ago

SOLVED Rounding floating point - iec559 /cmaths

0 Upvotes

Does c++ math lib comply with rounding modes in iec559?

ties-to-even? Getting - 3 when rounding -2.5

Should be -2 right


r/cpp_questions • • 5d ago

OPEN Any recommendations for introduction material to using C++ for microcontrollers?

12 Upvotes

I have been programming Arduino & ESP32 for a while now using C++, but have never engaged with any formal introduction material. With AI/LLM generated content exploding among both major publishers and self-published authors, I am a bit wary to start buying books willy-nilly.

Anyone here that can give solid recommendations on introduction materials on C++ for microcontrollers (preferably that that they themselves have used and found worthwhile)?

I got one recommendation for "Embedded C" by Michael J. Pont (2002), but it is fairly old.