r/cpp_questions • • 1h ago

OPEN starting cpp

• Upvotes

i want to start cpp, what should i mainly focus on first other than syntax?


r/cpp_questions • • 9h ago

OPEN After developing with C++ for 4 years what's the next step ?

11 Upvotes

I've been a C++ software developer/engineer for 4 and a half years now, and I feel that coding itself isn't a big skill anymore, I did many things here and there like reviewing, doing software architecture for some components etc... But I don't know what should I focus on exactly next with my foundation to keep up with the job market


r/cpp_questions • • 11h ago

OPEN Clang linter force int to sized int16 int32

0 Upvotes

Hello

I'm writing a firmware for esp and I want to have good practice to have a size fixed int for specific usage so I don't end with int or long long variable but instead a fixed size if I need only to go up to 25 element I don't need a full 32 bit word when a 8bit is enough

Is there a parameter to clang-tidy to force non lazy declaration or I need to always have it in mind ?


r/cpp_questions • • 12h ago

OPEN I need feedback on my project

5 Upvotes

Hey guys! I just started learning cpp and I've been working on a little project using functions, structs and conditional statements. It might seem stupid but I'm not willing to use AI for this project, I'd rather to get feedback from actual people so if there's anyone that can help me , I'd appreciate it:)♡


r/cpp_questions • • 14h ago

OPEN Best YouTube video to learn C++ pointers with full theory?

0 Upvotes

Hey guys, I'm learning C++ and I want to learn pointers properly. Can you recommend me a good YouTube video that explains pointers from the basics with full theory and also teaches how to use them in actual C++ code? I want to understand how pointers work in memory, why we use them, and how to write code using them instead of just memorizing the syntax. A long video or a playlist is fine too.

Which one would you recommend? Thanks!


r/cpp_questions • • 21h ago

OPEN Best resources to learn OOPs in C++ from scratch!!

0 Upvotes

Hey everyone!

I'm looking for good resources to learn Object-Oriented Programming (OOP) in C++ properly.

I want to understand concepts like classes and objects, constructors and destructors, inheritance, polymorphism, abstraction, encapsulation, and pointers with objects.

I'd prefer resources that explain concepts clearly with practical code examples and exercises rather than just theory. YouTube playlists, websites, books, or structured courses are all welcome.

Thanks In Advance!


r/cpp_questions • • 1d ago

OPEN La méthode ultime pour maîtriser le C++ de zéro à expert !

8 Upvotes

Comment puis-je apprendre le C++ et quelle méthode d’apprentissage ainsi que quelles ressources (livres, exercices pratiques, projets et documentation) devrais-je utiliser pour progresser efficacement, comprendre les concepts en profondeur et développer une véritable maîtrise du langage ?


r/cpp_questions • • 1d ago

OPEN MinHook/Memory searching?

0 Upvotes

Hey there! So I made a post here about TS1's Legacy Collection, and so far, I have a working asi mod, but the problem I now have is searching the process memory for Sims.exe to find the bytes that I'm patching. Even though I know the address, it won't be the same address on Windows, or other configurations. I previously did a MH_CreateHook function, but the code results in this: "MH_ERROR_NOT_EXECUTABLE".

I have this code which patches out the debug objects flag being set to 0.

auto address = reinterpret_cast<void*>(debug_objects_address);
DWORD previousProtection{};
VirtualProtect(address, 7,  PAGE_READWRITE, &previousProtection);
memset(address, 0x90, 7);
VirtualProtect(address, 7,  previousProtection, &previousProtection);
printf("Patch successful.\n");

This code works completely fine, but I'm unsure on how to get the address via searching for the exact assembly code in bytes, anything I've looked online seem to only suggest ReadProcessMemory, but from what I was told, it's intended for different process, not the same one that's attached to the executable, as per my ASI mod.

Would using VirtualProtect before using the MH_CreateHook function work? Again though, I'm unsure how to search the game's memory while attached as a process.

Any help/advice would be greatly appreciated! :)


r/cpp_questions • • 2d ago

OPEN What is the meaning of ":"

8 Upvotes

im started to learning data structres and i saw an operator in loops and stuffs, but i really cant understand what is the meaning of it i dont wannt to say "just this" i wannt to learn the princple behind it

for example :

for (auto members : ids)

r/cpp_questions • • 2d ago

OPEN What is the best representation of a graph(the structure)

6 Upvotes

What is the best way to represent a graph where both nodes and edges carry rich data payloads (not just connectivity)?

My primary constraint is performance: I need ultra-low cache misses for fast, forward propagation from a given source node to the end of a subgraph.

If anyone has implemented a cache-friendly graph structure for traversal-heavy workloads, I'd love to see what layout or pattern you used.

Edit: To clarify the use case: I’m building a reactive evaluation graph. When a node's data changes, that change propagates downstream through connected edges, using edge metadata to compute transformations, until reaching the end of the subgraph. I need a memory layout that minimizes cache misses during these forward cascade passes.


r/cpp_questions • • 2d ago

OPEN What is everyone’s opinions on vulkan?

33 Upvotes

I am quite new and just finished learncpp.com and now want to get into graphics programming. While I heard there are easier libraries than vulkan that also work I am highly interested in it specifically. What are your thoughts and how was it when you used it(if you did)?


r/cpp_questions • • 2d ago

OPEN When should I switch from C to C++?

30 Upvotes

I've been learning C for a while and have written a few basic coreutils programs, like ls, rm, cat, wc and grep. I'm still learning, but I'm getting more comfortable with the language. I want to get into systems programming, so I decided to start with C. So far, I like it, but I also want to learn с++ at some point. How much more с should I learn before giving с++ a try? Should I keep building projects in C for now?


r/cpp_questions • • 3d ago

Why doesn't the compiler detect better instructions?

32 Upvotes

I have added assume in the c++ code, to let the compiler make assumptions that 0 < x <= y.
This shall imply that x%y == 0 is the same x == y . But if the compiler were to make the assumption, then a cmp / xor instruction should be preferred over a div / idiv instruction? However, the emitted assembly always has the integer division instructions

This is mainly out of curiosity on how the assume keyword works, what all optimisations it can enable, and whether compilers can deduce mathematical equivalents.

https://godbolt.org/z/e4zeodnnM

#include <iostream>


int main() {
    int32_t x, y;
    std::cin>>x>>y;
    [[assume(x > 0)]];
    [[assume(y > 0)]];
    [[assume(x <= y)]];

    if (x % y == 0) { 
        return 1;
    } else {
        return 5;
    }
}

r/cpp_questions • • 3d ago

OPEN How to use CreateThread and MH_CreateHook?

0 Upvotes

Hi there, I'm getting further along with my code and attempting to fix -debug_objects being intentionally disabled in The Sims Legacy Collection (It wasn't in Complete or earlier versions), but I'm currently stuck on CreateThead and how to call it, and with MH_CreateHook.

So far, I know that with MH_CreateHook, I need to pass 3 arguments, a pointer, the detour function that runs, and then a return function?

I have the base address pointer set to this:
uintptr_t startofexe = (uintptr_t)GetModuleHandle(NULL);

I also have a uintptr_t value for the offset of where the "mov PTR BYTE" code is, aka "dbgo_disa_offset".

This is the code that I'm running right now:

void* ForceDisaChecktoNOP;

void TestCodeStart() {
// Initialize MinHook.
  if (MH_Initialize() != MH_OK)
  {
    OutputDebugStringA("Failed to initialize MinHook\n");
    return;
  }
  else
  {
      OutputDebugStringA("MinHook started successfully!\n");
      if (MH_CreateHook(reinterpret_cast<LPVOID*>(startofexe + dbgo_disa_offset), &ForceDisaChecktoNOP, NULL) != MH_OK)
      {
        OutputDebugStringA("DEBUG OBJECTS FIX FAILED!!!!!!");
        return;
      }
      else
      {
        OutputDebugStringA("Fix hook successful! Check if value is correct: " + (startofexe + dbgo_disa_offset));
      }
      return;
  }
}

The if statement works, and does output that the "fix" failed, but I need help understanding what I need to do for the arguments for MH_CreateHook. Right now, I want to make sure that the if statement for MH_OK succeeds before writing any additional code in the ForceDisaCheckToNOP section, or at the very least know that the ForceDisaCheckToNOP function actually gets reached. I understand that I need a pointer, and most examples of code that others have posted show the first argument being the address to the function to be modified/replaced.

When I set the MH_CreateHook to be a status variable (example code below), it gives this:

"The specified pointer is invalid. It points to the address of non-allocated and/or a non-executable region."

MH_ERROR_NOT_EXECUTABLE

status = MH_CreateHook(...);
if (status != MH_OK) {
    OutputDebugStringA(MH_StatusToString(status));
}

Second and third arguments I do understand to an extent, but not quite.

Second arg is supposed to be a link to a function in the code that acts as a detour, so instead of the original function, this one occurs instead. Third arg is supposed to be a return arg to run the original code of some kind from what I've seen, but it's a little confusing to me.

In regards to CreateThread, I was told by u/hellosverre (thank you!) that I should use CreateThread in DLL_THREAD_ATTACH, however I'm not understanding the syntax, as in, are the arguments for CreateThread optional, and how would I call it to start code in another cpp script? I can do TestCodeStart(); fine from dllmain.cpp, but then that calls the script every time any/the asi code's thread attaches itself. Microsoft's support page on CreateThread wasn't exactly helpful as it just tells me what the function is, not how you call it.

Any help would be really appreciated! :)


r/cpp_questions • • 3d ago

SOLVED Can std::cin display user input?

2 Upvotes
/*Write a program that asks the user to enter a number, and then enter a second number.
The program should tell the user what the result of adding and subtracting the two numbers is.

The output of the program should match the following(assuming inputs of 6 and 4) :

Enter an integer : 6
Enter another integer : 4
6 + 4 is 10.
6 - 4 is 2.
Hint : To print a period and a newline, use ".\n", not '.\n'.*/

#include <iostream>

int main()

{

int num00{};

int num01{};



std::cout << "Enter an integer : ";

std::cin >> num00;

//std::cout << num00 << ".\\n";



std::cout << "Enter a second integer : ";

return 0;

}

Hello everyone. I'm trying to complete the quiz in the block comment above.

My problem is that I have the user's value printed twice.

One next to "Enter an integer : " and the next right under it.

I thought the second std::cout was causing this so I made it a comment, yet the user's value prints out as intended.

I do not understand how this is working. Thank you for in advance.


r/cpp_questions • • 3d ago

OPEN GPU high throughput programming vs CPU low latency programming

0 Upvotes

Which one is significantly more hirable and more open to entry level roles at this moment? What would you spend time focusing on?


r/cpp_questions • • 3d ago

OPEN C++ Build systems

28 Upvotes

I work with Java and Kotlin alongside C++ and recently discovered that Gradle also supports C++ projects.

I've always used CMake for C++ and noticed it seems to be the more common choice.

What advantages does CMake offer over Gradle for C++ development and are there situations where Gradle would be a better option?


r/cpp_questions • • 4d ago

OPEN Anyone ever run into Windows processes exiting with code 109 during a build?

0 Upvotes

Hey everyone,

I've been trying to figure out a weird Windows issue and I'm a bit stuck.

I'm working with some C/C++ tools on Windows x64, using MSVC and CMake. During certain builds, a few child/console-related processes exit with code 109, even though the compilation itself can finish successfully and the C tests give the expected results.

Other processes exit normally with code 0.

I know Windows error 109 is ERROR_BROKEN_PIPE, but I'm not sure whether that's actually related or if the process exit code means something else here.

I'm also using Windows Job Objects to track and clean up the processes.

Has anyone seen something like this before?

I'm especially curious how you'd figure out whether the 109 comes from the tool itself, a Windows console process, or the way the processes are launched and monitored.

Is there a particular tool or debugging approach you'd recommend?

I'd rather understand what's happening than just ignore the exit code.

Thanks in advance!


r/cpp_questions • • 4d ago

OPEN Non-Struct Memory Alignment

3 Upvotes

I am a little lost after trying to read a handful of online resources. Are local variables memory-aligned to their alignof()? I read that this is mostly implementation/platform-defined (no guarantees), but also the types must still be aligned? Those seem contradicting to me...

Assuming no optimizations (e.g., storing in registers, etc.), how would something like this look like according to the standard?

struct S 
{
  char c;
  int i;
};

int main()
{
  char c1;
  int i;
  char c2;
  S s;

  return 0;
}

Would there be 3 bytes of padding between `c1` & `i` and then another 3 bytes of padding between `c2` & `s`?


r/cpp_questions • • 4d ago

OPEN How to master c++

0 Upvotes

Any advices please. Sometimes when its my turn to write code of what im asked to write I suddenly forget what was i supposed to do. I know somethings but struggle coding. What are the best sources and ways to learn


r/cpp_questions • • 4d ago

OPEN How should I learn how to code?

0 Upvotes

I want to learn how to code an many people suggested I start with C++ if I want to learn the real deal. The problem is I've never done anything close to coding. I don't know where to learn it from, or how to learn it. I tried learning from learncpp.com but I find the lessons too dense, and hard to understand. Can anyone share their story of how they started coding and how they learnt how to code?


r/cpp_questions • • 4d ago

OPEN Starting from Zero in C++

14 Upvotes

Hi everyone! I’m pursuing CSE at a Tier-4 college and have zero programming knowledge. I’m entering the tech field for the first time and want to start with C++ from scratch.

What’s the best way to learn C++? Which free resources would you recommend, and what common mistakes should I avoid? Also, how should I build my coding and problem-solving skills to become internship- and job-ready?


r/cpp_questions • • 4d ago

OPEN What graphics library should I learn for C++?

40 Upvotes

I am currently learning C++ by myself and I want to start graphics.

I just need something simple that lets me have buttons.

btw I don't want to use VS Community Edition and my IDE is CLion

I mean a simple GUI library with 2D graphics, buttons and textboxes.


r/cpp_questions • • 4d ago

OPEN API design dilemma..

0 Upvotes

right now in vexa(my game/graphics library) how you initialize window with a renderer is rather straightforward:

```cpp
#include <vexa/vexa.hpp>

using namespace vexa;

int main()
{
Engine::Init(Engine::VIDEO);

Window window = Window().setSize({1280, 720}).setRenderer({}).create();

// ...

```
YES, it uses builder pattern, not very C++-ish but i like it.
However, there are two problems with it.
first one is that usually you have builder struct building to target type so that you dont need something like `.create()` that creates classic `if (m_created) ...` problem a.k.a two phase construction. but bigger problem that caused me two want to switch to this API style is about memory management. and it is now C++'s problem.. Even rust cant handle it, because this is what you tell it to do.
so lets dont talk too much:

```cpp

Engine::Init(Engine::FONT); // calls `TTF_Init();` by SDL_TTF behind the scenes

Font font = Font::Load("...");
...
Engine::Quit();
```

A Font has destructor running on scope exit. which means before font object gets destroyed on '}' Engine::Quit() so TTF_Quit() runs. You see, when Font object gets unloaded at scope end the subsystem is not live anymore, we get a segfault. to fix this i've made Engine have a Guard struct which does Engine::Quit() automatically. But then decided that this is not i want for my API. I would priorotize explicitness for the master deinitialization.

to fix this im thinking of new API design style:
```cpp
Window window = Engine::BuildWindow().setSize({1280, 720}).setRenderer().create();
```

where BuildWindow() returns WindowBuilder not a Window, unlike the previous(so bad) choice.
for fonts, as you might already guess:

```cpp
Font font = Engine::LoadFont("...");
```

which creates a font and returns reference to it, resulting Engine to know about font count and Quit or not based on that.

code: https://github.com/monjaris/vexa


r/cpp_questions • • 4d ago

OPEN Working on a 3D engine for school. If I have a moving rectangle and a moving circle, knowing their speed and movement, how would I know when exactly to bounce the circle off the rectangle ?

2 Upvotes

Apologies if my english is bad. I'm working on a game where you move a rectangle (it's technically not because it's 3D, but the Y values of all objects never change, so I technically only need to compute 2D collisions) and with it you punch a puck, and an opponent (robot) does the same as you, both trying to not make it pass their goal. I'm not sure how the game is called in english, but it looks like the retro game "Shufflepuck cafe". The puck (cylinder, but in this case we can consider it is a circle) moves in X and Z, and it is supposed to bounce off the rectangle. But the collision happens between two frames, and for extra precision, I need to know exactly when it happens so that I can place the puck back into the place it should be. Anyone has an idea of how it should be done ? I have no idea how I'm supposed to code that.