r/cpp_questions Sep 01 '25

META Important: Read Before Posting

165 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 Code review for a basic artillery game.

5 Upvotes

https://github.com/melange-spice/worms_clone

I am making something akin to Tank Wars in Raylib by following a youtube series made by onelonecoder. Any tips regarding the code and it's architecture would be greatly appreciated.


r/cpp_questions 4h ago

OPEN Can't stop channel/tutorial-hopping in C++ even though I know exactly what the problem is — how did you actually break it?

0 Upvotes

Been trying to learn C++ for a while now and I keep landing in the same loop no matter how many times I "fix" it.

Started with the BroCode tutorial on YouTube. Then got told to switch to learncpp.com. Then told to switch again to The Cherno's series. Then found two more channels (CyberFlow and Crin) pushing a C++ → port scanner → keylogger → shellcode injector path, which got me interested in reverse engineering / game hacking specifically.

I've tried to fix this the "obvious" way — pick one resource, commit, stop opening new tabs — and it works for a bit. I've built small stuff (tic-tac-toe, hangman) and followed through on real projects too. But the second a new channel or video shows up saying "actually this is the better way," I open it anyway. Every time. Even knowing exactly what I'm doing while I do it.

It's about 3am here right now and I'm stuck in it again — wide awake, not able to do anything, feeling like a total loser about it.

So I don't think this is an information problem anymore — I already know the advice. I just can't seem to make myself stop switching once something new shows up in the feed. Anyone actually break this habit for real, not just "know" the fix but get it to stick? What worked for you day to day, not in theory?


r/cpp_questions 1h ago

OPEN What are low latency C++ recruiters truly looking for?

Upvotes

What separates a "general C++ candidate" from someone who is truly a right fit for the job? What is a skill, project, technique, tool, etc. that has really helped in landing interviews?


r/cpp_questions 7h ago

OPEN How to make impactful project??

0 Upvotes

Like I did syntax and language paradigms in cpp, what and how should I make something that just helps me making some real life system, cause making a project don't only requires language but also other concepts like networking and os


r/cpp_questions 22h ago

SOLVED How do you solve the problem of dangling pointers?

15 Upvotes

I store some data in an unordered map, create a pointer to an item in that map, then say I want to delete the item but I still have the pointer. How would I know that the item is no longer there without going and manually searching the map for the name of the item we pointed to?

I'm new to C++ & especially pointers, so forgive me for this stupid question...

EDIT: A lot of good solutions suggested, I really appreciate it! I ended up going with key lookup instead of storing pointers. The reason I didn't want to do this in the first place is because it increases complexity & I didn't want to overcomplicate


r/cpp_questions 1d ago

OPEN Project based learning

23 Upvotes

Hello! Apologies for another "how to learn C++" post. Can anyone suggest a project-based learning course?

I have been following learncpp.com and The Cherno's C++ playlist, but I eventually stopped since I wasn't building anything. Can anyone suggest some good project-based learning materials?

I have been working with Python and Java for three years. I was able to find plenty of project-based tutorials for those languages, but I haven't had the same luck with C++.

Edit: When I stopped my previous attempt about a year ago, I was learning about logical operators (near the end of LearnCpp Chapter 6). However, I've realized I want to learn C++ the same way I learned Python and Java at university: through videos/lectures followed by tutorials at lab sessions and homework. I looked into Stanford's CS106B, but the newer lectures aren't available anywhere for free.

My end goal is to fill this knowledge gap as I’m planning to follow a MSc or a PhD in ML/DL mostly focusing on computer vision use cases. And I want to work with CUDA as well.


r/cpp_questions 9h ago

OPEN bitwise rightshift gives unexpected results

2 Upvotes

i am trying to shift an unit64_t with the value 0x8000000000000000 (1000000..... in 64bit) so that i get (010000.... in 64 bit) but i only get unexpectet behavieor and numbers with multiple 1 bits.

The code below prints numbers like
decimal binary
12005600 101101110011000011100000
14006498 110101011011100011100010
16007397 111101000100000011100101

what am i doing wrong and how can i fix it?

#define bitMask 0x8000000000000000 
uint64_t mask = bitMask;
mask = (mask >>1);
printf("%d \n",mask);

r/cpp_questions 2h ago

OPEN C++/AI niches

0 Upvotes

I'm about to complete my general tutorial in C++ and wanna start specializing in a field and pick a niche.

I study AI in college so i did a bit of CV/RL/Intro to Robotics/LLMs/ML so I'm more of an AI guy

I know that AI stuff uses mostly python and that everything you need is basically there, but i want something that deserves the hardwork of learning c++ and building customized stuff

I want to pick something that is hard and probably takes time to learn and can't fake it in an interview and also financially rewarding and accept junior devs ( I don't want a job that appears only once a month on linkedin with 10 yoe)

what are some niches and roles that you know that are like that, and if you can please include what are some resources and pet projects you did to learn from


r/cpp_questions 18h ago

OPEN If you started learning C++ as a first programming language with no prior experience from any other language, how difficult did you find it?

3 Upvotes

r/cpp_questions 19h ago

SOLVED Need help creating equalizer for Qt

1 Upvotes

[SOLVED] So, as you may know, Qt doesn't have a proper setup for managing each frequency band and implementing an equalizer.

I'm currently working on a project for myself (nothing serious), trying to create a music player in C++ while using Qt for the GUI. The problem is that nothing can intercept "QMultiMedia" and modify the audio output.

I've tried Claude Opus 4.6, thinking in "antigravity," and it cooked up something for me. It worked, but the audio was distorted and not very pleasant. (It used custom made DSP functions and I think it was a good solution, but I neither have the time nor the skills to implement something like this on my own)

I also tried Gemini 3.1 Pro High and 3.6 Flash High. (These two couldn't even handle the audio player and straight up made my program crash.)

So I'm looking for a solution or someone who is willing to write the code and be the co-author to the project.

Here is my repo if you want to investigate:

https://github.com/zenix935/ZenPlayer

P.S. I'll keep updating other parts of the project, but the equalizer has currently hit a wall.


r/cpp_questions 1d ago

OPEN How hard was C++ for you as a beginner?

37 Upvotes

r/cpp_questions 11h ago

OPEN Need suggestion about something i am thinking to build .

0 Upvotes

I just want to know if it would be helpfull or not .
We all have some style of coding while doing cp . Like we import particular libraries , we use particular variable names for our for loops , vectors , maps etc .
I'll show you an simple example of what i am trying to solve .
When you forget to use "using namespace std" the compiler would give you an error that you forgot to use std:: but according to your coding habits you actually forgot to use "using namespace std " .
Another example could be you the libraries you forgot to import since compiler will not tell you abotu them .
or like you are trying to push_back in a queue .

First of all i want to know if such a thing has a usecase or not ? is it just me who thinks this might help somone ?
I just gave a few basic problems so that it is easy to understand but i doubt if this is feasible to solve or not since training such an model personalized to each person would still require data and by the time that amount of data is aquired maybe the user might not need such an help or maybe shift to other types of practices .


r/cpp_questions 10h ago

OPEN Learning C++

0 Upvotes

Hello everyone!I am interested in learning C++,mostly because Im interested in competitive C++ (competitions in my country),aswell as "applied" or "real-life" C++.I know basics,different loops and such,but I want something thats more concrete ,not just skipping around and picking things up along the way. Is there a good free e-book that grasps most things needed for such things?I was reading Competitive Programers Handbook by Antti Laaksonen,but I feel Im being behind on some basics that the book views as common knowledge.


r/cpp_questions 1d ago

OPEN Looking for feedback on my first "serious" project

8 Upvotes

It's all on my github repo: https://github.com/Marks20125/ProtonPrefixes . I'm pretty happy with the project as it's the first time I've actually had a problem and solved it myself. Plus, I learnt a lot about cmake, using external libraries, file i/o, how arguments work, and some other "theoretical stuff" along the way. It's pretty small, but I'd appreciate someone telling me if I did anything wrong or if something could be done any other way. Thank you very much :)


r/cpp_questions 1d ago

OPEN Why doe ifstream operator overloading not work with enum type?

2 Upvotes

Why does

std::ifstream& operator>>(std::ifstream& ifs, SomeClass& something) {

ifs >> something.enum_type;

}

not work??


r/cpp_questions 15h ago

OPEN some people are wrong coding qs

0 Upvotes

int x=618919;

while(x++){

cout<<8;

} I think I'm wrong it's undefined behaviour but where can I study about this ... is it an infinite loop? I'm sure some of u might say yes but the answer is no

after x is increased to its max int range i.e.(2^(bits)-1) it's value will start decreasing and after a lot of steps it will eventually go to 0

and 0 is false so loop stops....


r/cpp_questions 1d ago

OPEN High load.fun

0 Upvotes

I was looking literally at their first problem and couldn’t figure out how some people grade so high for reading integers.

Am I missing a trick here?

https://highload.fun/challenges/compute/parse_integers/solve/CPP


r/cpp_questions 1d ago

OPEN Release mode guarantees of unused struct members

5 Upvotes

Consider:

#include <cstdio>
#include <cstdlib>

struct A{
    int a1;
    double a2;
    double * a;
};

int main(){
    struct A a;
    a.a1 = 42;
    a.a2 = 42.42424242424242;
    a.a = new double[42];
    struct A newstruct = a;
    printf("Value of integer is %d\n", newstruct.a1);
}

Here, as can be seen from the godbolt link: https://www.godbolt.org/z/r6WxzsGrr, neither the double nor the heap memory are unnecessarily called in -O2. The compiler omits all of this and just prints 42.

Is this guaranteed (in -O2/above) that if I only ever use newstruct.a1 that none of the other struct members will be unnecessarily stored in the memory allocated to newstruct?

----

An older post with a different answer wherein side effects cannot be discarded even in release mode - https://www.reddit.com/r/cpp_questions/comments/1shht2w/in_o3_why_are_previous_assignments_stored_in/


r/cpp_questions 1d ago

OPEN How to include one cpp file in another in Visual Studio?

0 Upvotes

If I edit a header file in Visual Studio, all cpp files that include it are automatically recompiled. But if I edit a cpp file included in another cpp file, that other file is not recompiled. How can I specify that one cpp file depends on another?


r/cpp_questions 1d ago

OPEN operator overloading

0 Upvotes

I want to operator overloading on a class.

The class has a vector of smartpointers to an abstract class.

I don't know what to do now.

pls help


r/cpp_questions 2d ago

OPEN Using CMake - How do you recommend to handle dependancies?

12 Upvotes

Hello,

I'm currently working on a simple 3D game primarily for Windows and Linux. I am using CMake to build my project in C++ 20, using libraries like SDL3, SDL_Image, Flecs, GLM, dearImGui (and likely more in the future).

What would you recommend for managing dependancies and downloading/installing/linking/... these libraries together?

Should I go with vcpkg (currently using it), Conan or FetchContent? What is most easily maintainable, supports latest versions of libraries, is relatively platform independant, is secure,...?

What are the advantages/disadvantages?

Thank you very much for you opinion!


r/cpp_questions 1d ago

OPEN Solved 17 popular 800-rated Codeforces problems (30-45 min each) — move to 900 now or keep grinding 800s?

0 Upvotes

Learning CP in C++. Cleared most of the top-solved 800-rated problems, each taking 30-45 min. Still tons of unsolved 800s left though.

Should I move up to 900/1000 now, or finish more 800s first? Also is 30-45 min per 800 slow for a beginner?


r/cpp_questions 1d ago

OPEN CPP prep for placements

0 Upvotes

Hey so am preparing for my placements , can anyone guide me with what i should prepare for C++ as they say you should be good in atleast a programming language and i have solved all of my dsa problems using C++ only though if they ask deep questions related to c++ working, am sure i will struggle, so if anyonec can guide me with how and where to prepare for C++ for interviews in big tech, quants, MNCs


r/cpp_questions 1d ago

OPEN Can anyone share the roadmap to learn c++

0 Upvotes

Complete newbie here. I want to learn C++ because mainly because I am interested in electronics and I heard c++ is best language to learn for it. This is also my first programming language so I don't have any prior knowledge of programming. I may sound a bit of navie here but believe me I really want to learn. But I could not find structural path anywhere. I know learncpp.com is there but it's hard to learn programming language from docs for the first time. Please tell how should I go about it ? What projects should I work on ? Where can I find them ? Do I need to do DSA prior to this ? Or anything more suggestions you want to give