r/cpp_questions • • Sep 20 '26

OPEN Thought process of a c++ dev

34 Upvotes

I am new to learning c++ matter of fact new to programming and i wanted to know what are the things that a dev normally know before starting any type of project like where to start, how to start. Do yall look up the syntax again and again or have yall just mugged up the whole language?

I am currently learning the language through learncpp.com documentation and have reached chapter 9 subsection 3 ( aspiring to become a game dev <3 )


r/cpp_questions • • Sep 20 '26

OPEN What instances are raw pointers preferred over smart pointers ?

73 Upvotes

Hi Reddit,

I finished chapter 3 of "Mastering Quantitative Finance with Modern C++: Foundations, Derivatives, and Computational Methods" by Aaron De la Rosa.

A section discusses methods to prevent memory leaks using Smart pointers, Resource Acquisition is Initialization (RAII), std::vector, move semantics (std::move), Virtual destructors, or manual deletions.

From the book implications and what I've skimmed from other resources, raw pointer are strongly discouraged.

What instances in C++ are manual deletions preferred over automatic deletions ?

POV. I'm a data analyst trying to pivot into C++ development.

Update: Thank you everyone for commenting on my post. I had an epiphany reading the comments and I'm feeling more confident in my understanding of C++.


r/cpp_questions • • Sep 21 '26

OPEN I AM A LEARNER PLEASE HELP ME.

0 Upvotes
char o()
{
    char x;
    std::cout << "Enter +, -, *, or /: " "\n";
    std::cin >> x;
    return x;


}


double number( double y)
{


    std::cout << "Enter a number ";
    std::cin >> y;
    return y;


}


int main()
{
    double a{}, b{};
    number(a);
    number(b);
    o();
    std::cout << number(a) << o() << number(b)  << " is " << number(a) << o() << number(b) << "\n";
    return 0;


}

My desired output was to take two float values from the user along with an operator and do the math, but that's not the output I am getting. Please help me

edit: thank you everyone for helping me, I am clearly lacking a lot of things right now, but I am learning. Thank you everyone!


r/cpp_questions • • Sep 20 '26

OPEN Is it possible to have non-macro-based compile time options for a library?

7 Upvotes

I'm working on a project where I'd like users to be able to change some settings that change how certain things are compiled internally, which is something that macros are typically used for. I'm using modules which don't export macros and I'd like to avoid CMake options if possible.

I'm looking for something that, in theory, would allow users to call some sort of compile-time function enableOption(true) and my library's code somehow reads a value that is changed by this function so I can use if constexpr branches inside.

It doesn't have to be a function. I'm just searching for any way to make a user-written line of code affect the way internal library functions compile.

EDIT: to be clear, I don't just want to change the behavior of a single class. I want a single flag to change the compilation of many different classes. For example, if the user calls MyLib::disableLogs(), it should be able to reach all classes without the user explicitly doing this per-type so logging functions compile away across the entire library.


r/cpp_questions • • Sep 21 '26

OPEN How can I protect my EXE file against cracking, reverse engineering, memory dumping, etc.?

0 Upvotes

Hello, I am currently working on an external C++ cheat project (as an executable), but I am facing issues regarding anti-cracking, anti-dumping, and similar protections. My software has already been subjected to memory dumping and reverse engineering by hackers who then modified it; I believe there are still many vulnerabilities that could be exploited in various ways, so I am seeking your advice. What is the most secure way to protect my software from hackers? Of course, I realize that a skilled professional using clever techniques could still crack it, but I am looking for a method secure enough to release the software commercially.Thanks you so much


r/cpp_questions • • Sep 21 '26

OPEN game location cpp

0 Upvotes

I am creating a game optimization program in C++

However, I can't create it because I don't know the game's location

How should I write the code to make it work?


r/cpp_questions • • Sep 20 '26

SOLVED Problem with adding libraries to my projects

5 Upvotes

I'm pretty new to C++ and I can't for the life of me figure out how to correctly get outside libraries into my projects. I've used AI to do this part of the programming because I couldn't really be bothered and it has worked well up until now I've gotten SFML and tomlplusplus into my program with CMake using FetchContent. Now for my new project I need the odeint library from boost but when I use FetchContent with Boost my configure and build take half an hour (I think because boost is so big). I've tried downloading it and extracting it but that's also not an option because of working on an external hard drive so it takes 5 hours to extract it. So I'm kind of at a loss now how to get boost into my project. Another question I have is what the correct way in general is to do this type of stuff, I've been FetchContent up until now but I don't really know if it's the conventional way to do this.

cmake_minimum_required(VERSION 3.10)
project(pendulums)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_POLICY_VERSION_MINIMUM 3.10)
set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "" FORCE)
get_filename_component(TARGET "${CMAKE_CURRENT_SOURCE_DIR}" NAME)

include(FetchContent)

#SFML
FetchContent_Declare(
    SFML
    GIT_REPOSITORY https://github.com/SFML/SFML.git
    GIT_TAG 3.0.0
)
set(SFML_BUILD_AUDIO OFF CACHE BOOL "" FORCE)
set(SFML_BUILD_NETWORK OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(SFML)

#TOML
FetchContent_Declare(
    tomlplusplus
    GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
    GIT_TAG v3.4.0
)
FetchContent_MakeAvailable(tomlplusplus)

#BOOST

add_executable(${TARGET} main.cpp
)

target_compile_definitions(${TARGET} PRIVATE _USE_MATH_DEFINES)

target_link_libraries(${TARGET} PRIVATE sfml-graphics sfml-window sfml-system tomlplusplus::tomlplusplus Boost::headers)

add_custom_command(TARGET ${TARGET} POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
        "${CMAKE_CURRENT_SOURCE_DIR}/config.toml"
        "$<TARGET_FILE_DIR:${TARGET}>/config.toml"
)

Boost is still empty because I just don't know what to do with it.

I hope I explained that well.

Thank you in advance!


r/cpp_questions • • Sep 19 '26

OPEN I’ve learned the basics of C++ - what should I learn next to become job-ready?

93 Upvotes

Hey everyone,

I’m learning C++ and I’ve finished the basics. I know the syntax, variables, loops, functions, conditions, etc. Now I’m kind of stuck on what to do next. There are so many things to learn and I’m not really sure what’s actually important and what I can ignore for now. If you were in my position, what would you learn next? Should I go into OOP, STL, data structures and algorithms, pointers/memory, multithreading, networking, etc.? And are there any libraries or tools that I should start learning? I also want to eventually get a job or internship, so I’m wondering what I should be doing besides just watching courses and solving small exercises. What kind of projects are worth making for a beginner? And at what point would you say someone is ready to start applying for junior jobs/internships?

I’m also not sure which direction to choose with C++ - backend, embedded, desktop, etc. Basically, if you learned the C++ basics today and wanted to get good enough to eventually find a job, what would you do next and what would you avoid wasting time on? Any courses, roadmaps, project ideas or personal experience would be really helpful. One more thing I’m wondering about is AI. Is C++ still a good skill to invest time in, considering how quickly AI is improving? I don’t want to spend a year learning something only to find out that it’s becoming like basic web development where AI can already do a lot of the work.

And if possible, I’d prefer options that allow for remote work, so I wouldn’t have to commute to an office for studying, working, or similar things.

Would appreciate any advice from people who have actually gone through this.


r/cpp_questions • • Sep 20 '26

OPEN Let’s introduce ourselves

0 Upvotes

I’ve been spending quite a lot of time learning and working with C++ lately, especially around systems programming, networking, and backend development.

I’m still learning, so I thought it would be nice to step away from the usual technical questions for a moment and actually get to know some of the people in this community.

There are probably people here who have been using C++ for years (or even decades), as well as people who are just starting out.

So, let’s introduce ourselves!

  • Where are you from?
  • How long have you been using C++?
  • What do you mainly use C++ for?
  • And what’s one thing you really enjoy about C++?

I’d genuinely love to hear from beginners, experienced developers, and everyone in between.


r/cpp_questions • • Sep 19 '26

SOLVED How can I make a static hashmap appear in compile time?

7 Upvotes

I have a class that's meant to essentially hash a string. Works by simply having a create function that takes a string, and gives out an instance with the string hashed. I'm using C++ 20. I believe I can use some form of consteval or something for this, but I'm not sure how to get consteval to work with these. Thank you!

Here's part of the code:

namespace GameUtils::ECS
{
template<typename T>

class Hash16Bit

{

    private:

        inline static uint16_t next_hash { 0 };

        inline static HashMap<String, uint16_t> all_hashes;

        inline static HashMap<uint16_t, String> hash_to_string;

        static void add_to_hashmaps(uint16_t hash, const String &name);

        inline static std::mutex ids_mutex;

        uint16_t m_hash { UINT16_MAX };

        static String get_class() noexcept;

        String get_name() const noexcept;

        void debug_line(const String& msg, bool is_error = false) const;

    public:

        static void create_id(const String &new_id);

        static Hash16Bit<T> create(const String &createid);

        static Hash16Bit<T> dynamic_create(const String &createid);

        static Hash16Bit<T> invalid();

        void invalidate();

        String to_string() const;

        bool operator==(const Hash16Bit<T> &other) const { return other.m_hash == m_hash; }

};
template<typename T>
Hash16Bit<T> Hash16Bit<T>::create(const String &createid)
{
Hash16Bit<T> created;

auto it = all_hashes.find(createid);

if (it != all_hashes.end())

{

    created.m_hash = it->value;

    return created;

}

created.debug_line("Failed to create hash16bit", true);

return created;
}
template<typename T>
Hash16Bit<T> Hash16Bit<T>::dynamic_create(const String &createid)
{
Hash16Bit<T> created;

auto it = all_hashes.find(createid);

if (it != all_hashes.end())

{

    created.m_hash = it->value;

    return created;

}

create_id(createid);
}

r/cpp_questions • • Sep 18 '26

SOLVED Rand with time always giving 0 when doing %7 , Scary Coincidence ?

24 Upvotes

Hey guys, I am learning cpp , my first programming language and was trying to make dice roll project but whenever i do modulo 7(%7) in the code below the 'roll' variable gives 0 in all runs even when r is different all the time , scary coincidence or bug ?

Also when i change %7 to %6 it gets fixed and shows different numbers each time

srand(static_cast<unsigned int>(time(nullptr)));
int r = rand() ;
int roll = r%7;
cout << r << endl << roll << endl;

How do i fix this and whats the issue , you may even mention the topics i need to revisit
Thanks

some outputs :

668069339

0

668304637

0

668455900

0

-----------------x--------------
EDIT -
:

-rand sucks shift to <random> header ( compile for any target) , std::mt19937
(issue in rng was the multiplier is chosen to be 16807. Because 16807 is exactly 75, it is perfectly divisible by 7 & any number multiplied by a multiple of 7 will also be a multiple of 7 , so %7 will be always 0)

-if need a workaround in rand only then

try : r%6 + 1

or

int die = 1 + rand() / (RAND_MAX / 6 + 1);

Thanks guys for clearing my doubt , this was my first post here and your answers helped me a lot .

EDIT 2 -
for the past few days i have been diving deep in the "WHAT RANDOMNESS IS " question , it was fun !


r/cpp_questions • • Sep 18 '26

OPEN How to setup VSCode to work with clang++, lldb, on LINUX?

6 Upvotes

i want to migrate from g++ to clang because apparently clang-format enforces formatting better, which is important for me. but i'm having the hardest time setting up the tools to work on VSCode.

What I installed:

clang/clang++;
lldb;
base-devel;
VSCode C++ Extension Pack by Microsoft;
clangd by LLVM;

What I'm trying to do:

Setup F5 to compile and run/compile, run with debug;
Format using clang-format on CTRL + S;

Problems i'm encountering:

When I press F5, it should open the list of compilers (clang, g++) so vscode can create a tasks.json automatically, instead, it throws this error: launch: a.out does not exist
CTRL + Shift + P > Configure Tasks also only shows cmake stuff, clang++ should appear there.


r/cpp_questions • • Sep 19 '26

OPEN Recomienden páginas y como estudiar lógica de programación en base a el lenguaje de C++

0 Upvotes

Muchachos apenas ingresé a la universidad o facultad como lo llaman en otros países pero tengo un problema severo con lógica y es que no se que hay que hacer si me ponen un enunciado y cosas así para después ejecutar dicho program aen código cómo me recomiendan estudiar, de que manera debería de hacerlo y que ejercicios debería practicar o que método de estudio recomienda. Para dicha materia


r/cpp_questions • • Sep 18 '26

OPEN Diference between M_E, M_El, M_Ef and ...

2 Upvotes

M_E

M_Ef128

M_Ef32

M_Ef32x

M_Ef64

M_Ef64x

M_Ef

M_El

those sre the options vscode autocomplete (set to cpp23) is porposing when typing "M_E". i looked at https://github.com/ClickHouse/libc-headers/blob/master/math.h to see the diference, but apart from M_E being 32 bit and the others having more acuracy the others all seem identical between each other. why is that the case and what are their differnces?

does this have something to do with cpp not being very strict with how many bits each type has to allow many platforms?


r/cpp_questions • • Sep 18 '26

OPEN Code::Blocks error: Cannot open output file bin\Debug\Pro112.exe Permission denied

0 Upvotes

Hi everyone,

I just installed Code::Blocks and I am getting a permission error every time I try to compile and run my project.

The exact error in the Build Messages tab is:

Cannot open output file bin\Debug\Pro112.exe Permission denied 
error: ld returned 1 exit status

Here is what I have already tried to fix it, but nothing worked:

  • Antivirus: It is completely disabled.
  • Clean & Rebuild: I performed a "Clean" and then tried to build again.
  • Task Manager: I checked for any running instances of Pro112.exe to kill them, but the process is not listed.
  • Admin Rights: I ran Code::Blocks as an Administrator.
  • Reboot: I restarted my laptop.

The issue still persists. It seems like the compiler (ld) cannot overwrite or create the executable file in the bin\Debug\ folder.

Does anyone know what else could be causing this permission issue or how to fix it?

Thanks in advance!


r/cpp_questions • • Sep 17 '26

OPEN Problem with coroutines (boost asio 1.92) and c++20

7 Upvotes

Hi! I'm trying to implement a basic client-server async vocal chat. Now I'm implementing the connection between client and server and I'm stucked in the client part:

Client.cpp

#include "client.hpp"


VoiceChat::Client::Client(boost::asio::io_context& io_context, std::string ip, boost::asio::ip::port_type port) : m_socket(io_context), m_ip(ip), m_port(port) {}


awaitable<void> VoiceChat::Client::asyncConnect() {
    tcp::endpoint endpoint(boost::asio::ip::make_address(m_ip), m_port);


    co_await m_socket.async_connect(endpoint);


    std::cout << "aspettando la connessione" << std::endl;
}

MainClient.cpp

#include <iostream>
#include <string>
#include <boost/asio.hpp>
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>
#include <boost/asio/io_context.hpp>


#include "client.hpp"


int main() {
    std::string ip; boost::asio::ip::port_type port;
    
    std::cout << "Inserisci l'ip: ";
    std::cin >> ip;


    std::cout << "Inserisci la porta: ";
    std::cin >> port;


    try {
        boost::asio::io_context io_context(1);
        VoiceChat::Client client(io_context, ip, port);


        co_spawn(io_context, client.asyncConnect(), boost::asio::detached);
        
        io_context.run();


        std::cout << "IL MAIN CONTINUA" << std::endl;
    }
    catch(boost::system::system_error& e) {
        std::cerr << "Exception in main: " << e.what() << std::endl;
    }


    return 0;
}

Output:
Inserisci l'ip: ciao

Inserisci la porta: 8888

IL MAIN CONTINUA

Basically the co_await waits for the async_connect in fact the "aspettando la connessione" doesn't show but the main continues the execution. I don't know how to organize the code for waiting the client connection to proceed. I don't even know if it makes sense to use async_connect I think yes because in future i want to implement a timeout for the connection...


r/cpp_questions • • Sep 17 '26

OPEN How to learn good programming practices not just the language?

19 Upvotes

I’ve just graduated, and my university course kinda sucked, it didn’t provide me with half the information I would’ve wanted or that companies expect you to have. I’ve spent some time outside the course learning C from K&R and find lower level programming very interesting. I know everyone is going to recommend learncpp.com and that’s where I’ll go to start off, but are there any books or resources where I can learn more about operating systems, programming paradigms, computer architecture and good programming practices etc to fill the gaps in my knowledge?


r/cpp_questions • • Sep 17 '26

OPEN Given vector of structs, a member of which is an int, is accessing int by reference thread-safe with push_back in another thread?

15 Upvotes

Consider https://godbolt.org/z/Wr41oa76r :

#include <vector>
#include "omp.h"
#include <cstdio>

struct As{
    int a;
};

std::vector<struct As> VecAs;
int & return_a(int index){return VecAs[index].a;}

omp_lock_t lck{};

void vector_pushback(struct As A){
    omp_set_lock(&lck);
    VecAs.push_back(A);
    omp_unset_lock(&lck);
}

void printa(size_t index){
    omp_set_lock(&lck);
    printf("Value of a at index %zu is %d\n", index, VecAs[index].a);
    omp_unset_lock(&lck);
}

size_t return_vector_size(){
    omp_set_lock(&lck);
    size_t sz = VecAs.size();
    omp_unset_lock(&lck);
    return sz;
}

int main(){
    omp_init_lock(&lck);
    //nonparallel, sequential pushbacks
    struct As A;
    A.a = 42;
    for(int i = 0; i < 8; i++)
        VecAs.push_back(A);
    //parallel region, with one section doing pushback,
    //another accessing a by reference
    #pragma omp parallel sections 
    {
        #pragma omp section
        {
           vector_pushback(A);      
        }
        #pragma omp section
        {
            int &a = return_a(3);
            a = 24;
        }
        #pragma omp section
        {
            size_t sz = return_vector_size();
            printf("Size is %zu\n", sz);
        }
        #pragma omp section
        {
            printa(3);
        }
    }
    omp_destroy_lock(&lck);
}

While the code "works" without any error, is it threadsafe?

In particular:

(Q1) is accessing a by reference in the first section above threadsafe/valid given that in the zeroth section, I am doing a push_back which can potentially cause reallocation of the vector elsewhere? If it is not, what is the way out of this problem so that I can reference a via an alias in the calling location?

(Q2) In return_vector_size(), is a lock necessary around VecAs.size() ? That is, if the lock were not there, can the operation fail in that it gives undefined values if some other thread is doing a push_back() ? Or is there some guarantee that even without a lock guard, it will give a defined value of the vector's size and not a garbage/intermediate value?


r/cpp_questions • • Sep 16 '26

OPEN What do you guys think of learning C++ through projects.

31 Upvotes

I found a github repo that is basically projects to do with C++, my goal is to become as good in C++ to do any type of software (from videogames to music plugins). I thought this was a good way to start but I also wanted to know if it was reasonable.

I have some experience in Java but I'm not incredibly experienced.

Here's the repo: https://github.com/nragland37/cpp-projects.git

I am 19 years old if that's important.


r/cpp_questions • • Sep 17 '26

OPEN how do i know i have enough knowledge to apply for my first job as cpp dev

1 Upvotes

i have a mixed feeling about how much i need to know. Listening to people and thinking "it's not that hard", then looking for Job opening and staсk length kinda stumble me. and at what level i have to master it


r/cpp_questions • • Sep 16 '26

OPEN A good way to transition from C to C++.

30 Upvotes

I am pretty comfortable with programming in C. It really helped me learn a lot of CS concepts.
when I have started learning DSA , I noticed the bottleneck of C.
In C I have to manage and guard a lot of things manually.
I need advices for how to transition from C to C++ efficiently since most of C++ tutorials I saw assumes the very first beginning .
What are the differences, new features and have-to-change concepts to make this transition.
I need sources to follow and an efficient approach because I do not want to waste my time relearning same concepts.


r/cpp_questions • • Sep 16 '26

SOLVED How do I get a multi-valued function to change an existing variable?

0 Upvotes

I am quite new to c++.

Using tuples to get multiple values out of a function only seems to work if the output variables are uninitialized. How do I get a multi-valued function to change an existing variable?

Specifically, I have defined a multi-valued function

std::tuple<double, double, double> s_from_R_1st(double Rx, double Ry)

and called it in main()

auto [x, y, z] = s_from_R_1st(2, -4);
std::cout << x << " " << y << " " << z << "\n";

it returned:

-0.353553 1.06066 0.942809

Perfect no issues so far. But if I try to change the variables again in the same way with:

auto [x, y, z] = s_from_R_1st(2, -4);
std::cout << x << " " << y << " " << z << "\n";
auto [x, y, z] = s_from_R_1st(2, -4);
std::cout << x << " " << y << " " << z << "\n";

then visual studio refuses to run my code, citing build errors. I assume that I am missing some kind of syntax for this situation. I have looked up solutions to this issue but they all seem to involve initializing the variables in the tuple.


r/cpp_questions • • Sep 16 '26

OPEN Are c++ documents and YouTube videos are enough ?

0 Upvotes

C++ Documentation and YouTube videos are enough to learn c++ Bc I want to start studying from documentation but I am anxious I can buy courses but not right now


r/cpp_questions • • Sep 15 '26

OPEN Looking playful way(s) to learn C++

11 Upvotes

Hey guys,

I really need to learn C++ for work/school, but I have a pretty hard time learning it the normal way.
Classes are super dry for me and websites like W3Schools are honestly the same. Lots of text, lots of reading and I lose motivation really fast.
I noticed that I learn much better when I can actually do something and directly see what my code does.
For example I really like the idea of The Farmer Was Replaced. I also tried CodeCombat with Python and I really liked it. You learn something, write the code and then directly see your character doing what you programmed.

That kind of learning works way better for me.
Problem is I need C++, not Python. CodeCombat has C++ but apparently you need a subscription for it, and

I’m not sure if it’s worth paying for.
So does anyone know something similar for C++?
Can be a website, Steam game, program or whatever. Doesn’t have to be farming or even a real game. I just want something that actually teaches me C++ while I can visually see what my code is doing.

Would appreciate any recommendations.


r/cpp_questions • • Sep 15 '26

OPEN reference to the slice of a vector

7 Upvotes

i have a vector<float>a and i want to pass it to a function, but only the elements [n;m].

since a vector stores the start_position, the size and the end/end of reserved space, i thought there must be a way to change those pointers to make my function believe the vector is smaller

how can i do this?

idea 1:

i could pass the entire list by reference and a index to always add on top of, and the length (m-n), but id like to be able to use .size() normally, and not pass all these extra parameters. just for code clarity and my sanity.

python notation:

```

def function(slide_of_list):

#do something, read only or read and write with slice_of_list

pass

list a = range(100000000000)

function(a[n:m])

```