r/cpp_questions

What library should I use for a long term 2D game project?

I'd like to start developing a strategy game in C++ in some time. I want it to include a big map, complex UI, AI and more. I already started learning raylib and it's pretty fun, but I'm not sure is it the best choice for a big project. I was also thinking about SFML. Should I use one of them or something different?

reddit.com
u/Janeq404 — 18 hours ago

C++ learning resources for someone who already knows a lot of C?

I wanted to get into C++ programming since I have bene programming in C for a while now, are there any good videos or resources tailored specifically to someone in a situation similar to this?

reddit.com
u/SeaInformation8764 — 23 hours ago

I think I'm still confused about the practical use of std::move

Note: I'm working in Visual Studio 2013 for reasons, so I'm using C++11.

I get the idea of transferring ownership, but I seem to be missing something. Here's some sample code (off the top of my head -- work makes it hard to share real code)

std::string tmp = std::to_string(i) + std::to_string(j);
if (someCondition()) {
    const std::string tmp2 = getSomeString();
    if (IsValidData(tmp2))
        tmp = std::move(tmp2);
    else if (i == 0 && j == 0)
        tmp = "??";
    else
        tmp = std::move(tmp2);
}

Coverity is telling me that the std::move calls are ineffective. I added them because of Coverity suggestions on an earlier version of this code, and it made sense then. Since std::string has to own its data, I don't understand how the move is ineffective? Is it because I don't do anything else with tmp2, and thus ownership isn't an issue?

reddit.com
u/pfp-disciple — 1 day ago

Need guidance for transitioning from DSA to cpp developer.

I have been doing DSA in C++ for almost 1.5 years and now I’m quite comfortable with the language. I want to move forward into real C++ development and would like advice regarding the tech stack I should learn.

What frameworks/libraries should I focus on?

What types of projects should I build to become industry-ready as a C++ developer?

reddit.com
u/Federal_Table2889 — 1 day ago

Warning on optional<int> - bool comparison?

I was trying to make sense of what happens when one compares std::optional<int> with bool:

https://godbolt.org/z/597Meh718

Apparently there's some nasty implicit conversion going on under the hood, details of which I don't quite understand.

But from more practical point of view: How to prevent doing this by mistake? MSVC warns by default. Is it possible I enable some similar warning in GCC / Clang? If not why, is there some undesirable false-positive as a result?

u/vid512 — 1 day ago

Good materials/resources to learn object lifetime properly for the Win32 API

Hi everyone,

so basically in a nutshell, I am a C# (.NET) developer with unfortunately only 2 years of programming. Only recently, have I stumbled into low level C programming with Windows API as part of my hobby, and as part of my incoming low level win32 API project, I would like to transition into C++. I picked up a book or two on Windows API programming, but since I just started with C++, so I am lacking basics in that department too in order to progress. I have tried to read up on RAII yesterday and I understand the concept/premise of it, but naturally, i am struggling to understand, how to implement object lifetime properly, especially when i am going to be wrapping Windows API into objects.

I wanted to ask, if anyone has good materials for beginners like me to learn and understand this concept properly.

Thanks

reddit.com
u/Moonrider64 — 1 day ago

Looking for C++20 feedback on a small SDL3 game

I’ve been working on a small Defender-style arcade game, mostly as a learning project to improve my C++ skills.

My main question is: does this look like reasonably idiomatic modern C++ for a small SDL game, or are there design/ownership issues I should fix before building future projects from this style?

GitHub: https://github.com/nathan-websculpt/sdl3-defender-v3

The game itself is intentionally small, but I’ve tried to treat the codebase as more than a throwaway prototype. I’m trying to make the structure, contracts, tooling, and resource ownership as professional as possible.

I would appreciate C++-focused feedback on things like:

  • Whether the project structure and responsibility boundaries make sense
  • Whether my ownership/resource-management patterns are idiomatic C++20
  • Whether the SDL3-specific code is isolated cleanly from the game/simulation logic
  • Whether the public APIs, naming, and contracts are clear
  • Whether anything looks overengineered, underengineered, brittle, or hard to maintain
  • Whether the CMake/vcpkg/tooling setup looks reasonable from a C++ project perspective

Some context about the project:

  • SDL3 renderer/window/audio/input integration
  • Fixed-step simulation loop
  • Mostly SDL-free simulation layer
  • RAII-style ownership for SDL resources
  • High-score persistence
  • CMake/vcpkg build setup
  • Debug/Release scripts
  • Tests and Windows release smoke checks
  • Packaged Windows release artifacts

I realize that reviewing a full repository is a big ask, so feedback on even one subsystem, one ownership pattern, one header/API, or one build/test pattern would be useful.

reddit.com
u/web_sculpt — 1 day ago

Looking for C++ Game Engines for using on low end laptop

So lately I've started learning C++ for Unreal Engine. I'm going to my hometown for a week and I can't bring my desktop PC, so I'll be bringing my old laptop — an Acer Aspire Switch 10 E (SW3-013). It has a really low-end CPU and only 2GB of DDR3 RAM. Any ideas on what I can do with it during this time? I'm currently thinking of installing a lightweight IDE (like Zed) and practicing C++ with Clang — but I'm open to other suggestions too.

reddit.com
u/Lilly_Smithe — 3 days ago

C++ Studying

I really struggled with c++ so I was wondering if there are any websites that helped you guys study. I’ve heard great things about LearnCPP, and I’m planning to use it, but I would also like to get a more interactive website since I have heard LearnCPP is very text heavy. I appreciate any feedback.

reddit.com
u/Competitive_Sock2525 — 2 days ago

What direction to go?

I am an undergraduate computer science student just completed my first semester heading into the next semester for year one and so far nothing Programming just maths and theory stuff… Throughout this 3 week vacation we had, I was like why not learn C++ since I’d be learning it along the way… I got into it and oh man I actually love the language I’ve studied to use arrays, pointers, structs and functions (I can’t say I’m advanced because how do you know what is advanced in C++ lol) and and learnt a few headers like the fstream, cctype and string ones, I honest don’t know what to peruse as a career so that why me opting for Computer Science in the first place… I like playing games and deciding Game Dev but I also think maybe something about databases and stuff would be cool too… so with my progress what do I need to keep doing or should do to progress better (I learn from various sources so I can’t give a particular place I’m learning the language) Fahh this is very long if you read it this far please share any opinion you have and thanks again

reddit.com
u/BronzeKillerX — 3 days ago

Shared structs and different compiler options

Hello. I am dealing with a largish, legacy code base and I am trying to make some common vocabulary structs that contain data passed between major components. These are the system architecture types for communication, not anything used in intensive computation.
We had a new multi-address space RTOS, so we were starting to use separate address spaces to ensure that our code communicates only using known interfaces (no globals, hidden in singletons or whatever). As it so happens, we are moving back to a single address space RTOS, but I am still making these structs as if they are going to be used by separately compiled components. I plan to make each major component compile into a library that is used by the application.
This is all to setup my question! I have recently learned that I may need to protect against different compiler options being used in different components. We might want to change optimization for a particular component, for example, after we get rid of any old UB in it. I have heard that aggressive optimization might do all kinds of interesting stuff with a struct underlying layout. This might not match what another component's compiler options generate.
It seems like I am fighting the compiler a little bit by adding alignas() in some places and having static_assert() to make sure the struct is how we want, i.e. to undo any optimization for that type. It can also be stated that we are using the binary format as a cheap serialization between components, and so that is why I might be fighting the compiler this way. Compiling things independently and allowing different compiler options is like making different programs and then expecting the raw binary to be the serialization still (like you can inside a program compiled all together).
It feels dumb! What are you people doing in these cases?
Thanks!

reddit.com
u/ConnectHat4222 — 2 days ago

PFRAII (Pre-emptive Fatigue Reduction Arrangement Is Initialization) :D

{update}: I got it now. This is a wrong design. Thank you guys!

{original post}:
This is about using custom short aliases of C++ types via a namespace. I am not saying it's perfect but here me out.

The goal is achieving minimum number of keystrokes when repeatedly writing some of these boring big-ass type-names. (the auto keyword is too ambiguous to be used most of the time)

I have created these weird looking type aliases that I am thinking to use everywhere.
https://godbolt.org/z/4x1fzdbY5

Design:
0: Every type is const by default.
1: A type name ending with 'm' means the object is mutable.
2: A type name ending with 'r' means the object is reference to this type.
3: A type name ending with 'mr' means the object is mutable and reference to this type.

I mean even though we are used to it yet literally who the even loves to write something like this:
const std::unordered_map&lt;std::uint32_t, std::vector&lt;std::vector&lt;uint64_t&gt;&gt;&gt;

when,
mp&lt;i32um, vc&lt;vc&lt;i64um&gt;&gt;&gt;
is easier to look at, more code fits into the screen and once you get comfortable with new terminology; it should take no more than a day, your eyes get to easily focus more on the expressions and logic rather than spending more time on scanning the code.

Yes, I acknowledge the risk of global namespace pollution.
but this should work fine if all of the following is true, right!?

0: Never use "using namespace <namespace-name>" at the global scope.
1: Never use variable/constants at the global scope.
2: No declaration/definition of free function, class, struct, enum, enum class whatever at the global scope.
3: Only things that can exist at global scope is definition of namespaces.
4: All free constants/variables, free functions, classes, structures, enum, enum class etc exist only inside its respective namespace.

Fox example, the NSTypeAlias namespace will be used as:

namespace NSMyCustomUtility::FileIO {
  using namespace NSTypeAlias;
          
}

or

int main(){
  using namespace NSTypeAlias;
  
  return 0;
}

or

namespace NSMyFileSystem {
 using namespace NSTypeAlias;
    
 class FileSystemX1{
        
 }
}

And in case the name collision does happen some day because we found a library to collide with we can always use it as

using Tpi32m = NSTypeAlias::i32m; or something like that inside that specific inner context whereever the name collision occurs.

or we simply revert to the stock C++ type names within that particular context and use a comment that says, /* can't use the custom type names because of collision */

because nothing is perfect and is ever going to be perfect anyway.

or, am I coping hard and bringing the other foot of mine into the possible blast radius as well? lol

u/emfloured — 3 days ago

About learning CPP with projects vs following tutorials relatively strictly

I'm currently in the process of working my way through learncpp.com (chapter 12) and I was reading some older threads from people discussing tutorials vs learning by doing (assisted by tutorials). It seems a lot of people recommended mostly doing "projects" implementing the lessons. However right now, I can't really Imagine doing a larger project than the questions at the end of the chapter, just because I still think I'm pretty limited on knowledge. So I was curious, when should i start doing some kind of project, and perhaps what did you guys do as this kind of learning project?

reddit.com
u/Sad_Mountain — 2 days ago

WHO THE HELL IS USING std::print

I hate to say it… but using `std::print` / `std::println` in C++ feels wrong to me.

I know they’re modern.
I know they’re “cleaner”.
But every time I see them in code… something feels off.

Maybe it’s because C++ was never just about convenience.
It was about control.

And somehow:

std::cout &lt;&lt; value &lt;&lt; '\\n';

still feels more *C++* than:

std::println("{}", value);

Even compile-time thoughts start creeping in.
What gets instantiated?
What gets parsed?
What hidden machinery am I pulling in just to print text?

It’s strange.
Technically better doesn’t always *feel* better.

Sometimes old C++ idioms just fit the language soul more.I hate to say it… but using std::print / std::println in C++ feels wrong to me.I know they’re modern.
I know they’re “cleaner”.
But every time I see them in code… something feels off.Maybe it’s because C++ was never just about convenience.
It was about control.And somehow:std::cout << value << '\\n';
still feels more C++ than:std::println("{}", value);
Even compile-time thoughts start creeping in.
What gets instantiated?
What gets parsed?
What hidden machinery am I pulling in just to print text?It’s strange.
Technically better doesn’t always feel better.Sometimes old C++ idioms just fit the language soul more.

reddit.com
u/Appropriate-Bill9165 — 3 days ago

I need help....

Can anyone help me with this problem? My code has an error code of E0291. It says "no default constructor exists for class "juce::AudioProcessorValueTreeState"

If anyone has experience in C++ and audio programming, can you help me???

reddit.com
u/PenaltyPodcast — 2 days ago
▲ 0 r/cpp_questions+1 crossposts

How I Set Up VS Code for Competitive Programming / DSA in C++ (Windows)

After trying many setups, I finally created a clean VS Code environment for C++ + Competitive Programming.

Now I have:

  • Separate folders for source code and .exe
  • One-click compile & run
  • input.txt and output.txt
  • GitHub integration
  • Clean project structure

This setup feels much better than online IDEs for serious DSA practice.

1. Install VS Code

Download:

https://code.visualstudio.com/

Install normally.

2. Install MinGW (g++ compiler)

Download MinGW:

https://sourceforge.net/projects/mingw/

While installing select:

  • mingw32-gcc-g++

After installation, your compiler path usually becomes:

C:\MinGW\bin

3. Add MinGW to PATH

Search:

Environment Variables

Open:

Edit the system environment variables

Then:

Environment Variables
→ Path
→ Edit
→ New

Add:

C:\MinGW\bin

Click OK everywhere.

Restart VS Code completely.

4. Verify Compiler

Open terminal in VS Code:

Ctrl + `

Run:

g++ --version

If installed correctly, it will show GCC version.

5. Install VS Code Extensions

Install these:

  • C/C++
  • Code Runner (optional)

6. Create Folder Structure

I use this structure:

DSA/
│
├── code/
│
├── exe/
│
├── input.txt
├── output.txt
│
├── .vscode/
│   └── tasks.json
│
├── .gitignore
└── README.md

This keeps everything clean.

7. Setup Input / Output Redirection

Inside every CPP file:

freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);

Now:

  • input comes from input.txt
  • output goes to output.txt

No need to type input repeatedly in terminal.

8. Create tasks.json for One-Key Run

Create:

.vscode/tasks.json

Paste this:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run C++",
            "type": "shell",
            "command": "cmd",
            "args": [
                "/c",
                "g++ \"${file}\" -o exe\\${fileBasenameNoExtension}.exe &amp;&amp; exe\\${fileBasenameNoExtension}.exe"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal": "always",
                "panel": "shared"
            },
            "problemMatcher": []
        }
    ]
}

Now press:

Ctrl + Shift + B

and current file automatically:

  • compiles
  • generates .exe
  • runs

9. Recommended VS Code Layout

I split the screen into 3 sections:

Left:

code.cpp

Top-right:

input.txt

Bottom-right:

output.txt

Use:

Ctrl + \

to split editor.

This setup is AMAZING for CP practice.

10. GitHub Setup

Initialize repo:

git init
git add .
git commit -m "Initial commit"

Connect GitHub:

git remote add origin YOUR_REPO_URL
git branch -M main
git push -u origin main

Future workflow:

git add .
git commit -m "Solved new problem"
git push

11. Important .gitignore

Create:

.gitignore

Add:

*.exe
output.txt

Don’t push generated binaries.

Final Thoughts

This setup improved my workflow A LOT.

Benefits:

  • cleaner practice
  • reusable workflow
  • faster debugging
  • organized DSA repo
  • GitHub tracking
  • professional structure

If anyone wants, I can also share:

  • VS Code settings
  • debugging setup
  • contest workflow
u/Fresh-Potato-3402 — 3 days ago

Should I use SDL, GLFW or SFML for 2D game?

I'm a CS student who recently did completed the C++ course and want to go further. I want to learn how make a 2D game from scratch with OpenGL, and eventually a 3D one. I also think that doing my own games during my free times would be great to build a portfolio on my GitHub. I'm still unsure which libraries should I use as a beginner.

reddit.com
u/AUnknownGuy — 3 days ago

Looking for structured, high-quality Intermediate to Advanced C++ courses

Hey everyone,

I’m looking to take my programming skills to the next level. I already have a solid grasp of the absolute basics but now I want to get into intermediate and eventually advanced concepts for C++

My main issue right now is finding the right platform. I’m pretty reluctant to buy courses on Udemy upfront because the quality varies so wildly, and I’d much rather test out the teaching style first. I’m looking for suggestions on structured courses (video or text-based) that focus heavily on intermediate-to-advanced topics. I’ve already checked out the usual recommendations but I’m after something more structured I can use as a base point

reddit.com
u/420ball-sniffer69 — 3 days ago

Has anyone seen build time improvements w/ C++20 modules?

Been looking into C++20 modules as a way to get our build times down. I get the pitch. Modules compile once and the result gets reused rather than every translation unit going through the same headers.

We're on a ~300k loc codebase, CMake + Ninja, MSVC on Windows. Clean builds are sitting around 12 minutes. Modules support has felt fragile every time I've poked at it which has made me hesitant to commit.

Has anyone here actually seen build time gains on a codebase of real size, and whether a migration is realistic or if mixing with legacy headers makes everything worse.

reddit.com
u/MissNobodyyyy — 4 days ago