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 • • 18h ago

OPEN Is it still worth learning C++ 11 or should i start with C++ 17 and later?

14 Upvotes

r/cpp_questions • • 5h ago

OPEN Audio Mixing Libraries for C++

1 Upvotes

Hi, I'm trying to make a DJ deck as a fidget toy but I'm having trouble getting features (like reverse, speed up/down, etc.) to work on MP3 files. Wanted to ask if there were any popular audio mixing libraries I should check out to get these features + more to work on a Raspberrypi/Arduino set up. I already own a DY-HV20T and a DFPlayer if that helps at all.


r/cpp_questions • • 7h ago

OPEN why my program give output 8 and 3 written in cpp , I know it is wrong I trying something . I don't initialise z here but it take automatically zero and give 8 , I do chatgpt I didn't get it can you give reason ?? or logic I don't know

0 Upvotes

#include <iostream>
using namespace std;
int addDigits(int num)
{
int a, b = 0, z;

while (num != 0)
{
a = num % 10;
z = a + z;
num = num / 10;
cout << a << endl;
}

return z;
}
int main()
{
addDigits(38);
return 0;
}

output
8
3


r/cpp_questions • • 3h ago

OPEN Is having multiple ways to implement the same thing a good feature of C++? Or is it confusing?

0 Upvotes

I'm a C++ programmer and Go developer. I started using C++ three years ago as a competitive programmer.

C++ is a programming language with so much tech debt that there are even three or more ways to initialize a variable. Its multiple programming paradigms can also be overwhelming sometimes.

I know this is for backward compatibility, and programmers can still choose how they program in C++.

But... this intentional design still feels confusing to me and looks disorganized.

I'm curious about your opinion on this.


r/cpp_questions • • 1d ago

OPEN Getting better at C++ for coding interviews?

18 Upvotes

I dont mean Leetcode, but enough to be able to debug thoroughly, write out basic functions, etc. Not DSA, but just smaller code snippets, anywhere from 20-100 lines, where an interviewer says do this for me, or debug this.

How can I get better at that? right now I've mostly done coursework involving it (long time ago), but not much internship experience using cpp


r/cpp_questions • • 23h ago

OPEN Programmatically opening a new terminal window

3 Upvotes

I've been messing around with FTXUI, and I am wondering if it is possible for my apps to open a new terminal window and run there, instead of using the current terminal window.

An example of what I mean is what happens when opening vim. If I open vim through the terminal, it takes over the current window, like my FTXUI apps currently do. If I use the desktop shortcut, vim opens a new terminal window for itself, which closes upon closing vim. This is what I want to do.

Can anyone give me a few pointers?


r/cpp_questions • • 22h ago

SOLVED I don't know what's missing here

0 Upvotes

This code is not working and i don't know why (visual studio).

#include <iostream>
#include <string>

int main()
{
std::string Dividendo;
std::string Divisor;

std::string Cociente;
std::string Resto;

std::cout << "dividendo?";
std::cin >> Dividendo;
int Dividendo = Dividendo;

std::cout << "divisor?";
std::cin >> Divisor;
int Divisor = Divisor;

int Cociente = Dividendo/Divisor;
int Resto = Dividendo%Divisor;

std::cout << Cociente << " , " << Resto << std::endl;



}

What happened?


r/cpp_questions • • 22h ago

OPEN Ways to grant special access to test/debug code.

1 Upvotes

In the following testing code C_string_value is a class with a protected member function kind() that supplies info about the internal implementation state. I access that via the member pointer trick. And I wonder if this is a good way to grant special access to testing code, while keeping ordinary code restricted to the public interface, and also whether you use some alternative such as (1) just make that internal functionality public, or (2) be-friend a class template Odin_, Hugin_ or Munin_, or (3) nasty formally UB preprocessor tricks, or even (4) litb's all valid C++ trick for accessing private members, or (5) something else?

#include <cppm/parameter_passing/in_.hpp>
#include <cppm/text/C_string_value.hpp>
using   cppm::in_,
        cppm::C_string_value;

#include <print>
#include <string>
using   std::print,
        std::string;

auto kind_of( in_<C_string_value> s )   // The internal kind: view of literal, or shared ptr.
{
    struct Access: C_string_value
    {
        static auto kind_of( in_<C_string_value> s ) -> int { return (s.*&Access::kind)(); }
    };

    return Access::kind_of( s );
}

auto main() -> int
{
    const auto lit = C_string_value( "Literal" );
    const auto dyn = C_string_value( +"Dynamic" );
    const auto str = C_string_value( std::string( "std::string rvalue" ) );
    const string ssl = "std::string lvalue";
    const auto str2 = C_string_value( ssl );

    print( "{} -> {}.\n", kind_of( lit ), lit.std_sv() );      // 0 -> Literal.
    print( "{} -> {}.\n", kind_of( dyn ), dyn.std_sv() );      // 1 -> Dynamic.
    print( "{} -> {}.\n", kind_of( str ), str.std_sv() );      // 1 -> std::string rvalue.
    print( "{} -> {}.\n", kind_of( str2 ), str2.std_sv() );    // 1 -> std::string lvalue.
}

EDIT (added):

I avoid conditional code on principle; to me it's so a big a no no that I didn't even include it in my list of 4 alternatives. That avoidance is about complexity, and that conditional code can change the binary layout, introduce name collisions, whatnot.

The nice thing I see about the member pointer trick, for larger scale development, is that access functions like the shown kind_of can be automatically generated in the testing/debugging code without affecting the original class.


r/cpp_questions • • 23h ago

OPEN Choosing the Right Tech Stack for My First Full-Stack Project

0 Upvotes

I have learned the basics of programming and web development, and I want to build my first real-world full-stack project: an e-commerce website for a clothing brand, for which I already have a client.

I want to make it professional, from UI/UX design and database architecture to security, testing, and deployment. What tech stack would you recommend?

Finally, how important is the tech stack to recruiters? If a company uses different technologies from those I used in my project, could this put me at a disadvantage during a technical interview? What advice would you give me to make this project stand out in my portfolio and prepare for interviews?

Thank you in advance for your advice!


r/cpp_questions • • 1d ago

OPEN problem solving!!

0 Upvotes

guys.. i was doing hackerRank but there are many question which are been asked to solve by pointers and all but i am very new to coding and cpp i am easily able to do it by other alternatives!!
so i am wrong solving those q's by other method or what!!
and i would like to solve the questions in team?
any of uh interested?


r/cpp_questions • • 1d ago

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

9 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 • • 1d ago

OPEN I am searching for a cpp "engine"

4 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 • • 2d ago

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

4 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 • • 2d ago

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

13 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 How to master? What courses to watch?

0 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 • • 2d 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 • • 2d ago

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

24 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 • • 3d ago

OPEN Guidelines for constexpr

10 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 • • 3d 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 • • 3d 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 • • 4d ago

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

50 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 • • 3d 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 • • 4d ago

OPEN need guidance

5 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 • • 3d ago

OPEN C++programing

0 Upvotes

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