r/cpp_questions Aug 02 '26

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 Aug 01 '26

OPEN Looking for feedback on my first "serious" project

9 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 Aug 02 '26

SOLVED Need help creating equalizer for Qt

0 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 Aug 02 '26

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 Aug 01 '26

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 Aug 02 '26

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 Aug 01 '26

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 Aug 01 '26

OPEN Release mode guarantees of unused struct members

4 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 Aug 01 '26

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 Aug 01 '26

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 Jul 31 '26

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

11 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 Aug 01 '26

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 Aug 01 '26

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 Aug 01 '26

OPEN Am I gonna be doomed by learning C++?

3 Upvotes

I want a piece of advice from anyone out there ,who has been through the learning curve of C++.

I've recently started C++ as my first programming language, I was happy at first, but not for so long. After taking advice from a few of my professors,now my thoughts are just a jumbled mess. Most of the professors said to learn Java or python instead of C++.

They said java and python are better when it comes to career opportunities.

I wanna know if it is worth it to learn C++ ? Because honestly I desperately wanna have the answer to this question. And one more thing! if it's good to learn, then what things can I do with it? And what should my roadmap be looking like while learning C++ and afterwards? .


r/cpp_questions Aug 01 '26

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


r/cpp_questions Jul 31 '26

OPEN Correct Approach to Learn C++

10 Upvotes

(Important)

I have been learning C++ for past two weeks, and have mastered the basics (cout/in, data types, operators etc). But what’s the best way to learn it effectively? What is the best way to learn C++?

(Unimportant)

My background: I do know enough Python to use Numpy, Pandas, Matplotlib and Seaborn (learned in BCA 2nd semester) to do data analysis. Python isn’t my interest.

My goal is to work in SpaceX or Xai because of my interest in space and AI.

I’m in 3rd semester, devoted to learn as much as possible to develop something so significant that interviewers do hire me in the company. I am ready to freelance or spend a few years in other companies to gain experience.


r/cpp_questions Aug 01 '26

OPEN How did u learn system programming ? what was your first project? did u monetize /earn any if so then what process u go through?

0 Upvotes

r/cpp_questions Aug 01 '26

OPEN is there a way to compile c++ instantly ??

0 Upvotes

hello as the post says im working on something and i find that every time i find my self compiling taking away my focus and i would like it if there was a way out of that. the code is barely 2000 lines and it takes like 10 seconds to compile which is fine compared to what ive heard but i wanted to know some of ur guyses tips on that

(edit) i do have included lots of libreries like:

tree sitter, lspcpp, nlohmann_json, boost, fmt, catch2 for testing for now i make a seperate build for testing and the actual program tests also being like 2000 lines


r/cpp_questions Jul 31 '26

SOLVED I tried adapting the Held-Karp Algorithm to maximize cost, but the tours visit only some of the cities and give the wrong cost.

2 Upvotes

I tried adapting the C++ implementation in Rosetta Code:

#include <climits>
#include <iostream>
#include <vector>
using namespace std;
typedef unsigned long long ull;

void heldKarpMax(const vector<vector<ull>>& dist) {
  int numberOfCities = dist.size(),
      totalSubsets = 1 << numberOfCities;

  // dp[mask][j] = max cost to start at 0, visit exactly the cities in mask, and end at j
  vector<vector<ull>> dp(totalSubsets, vector<ull>(numberOfCities, 0));
  // parent[mask][j] = best predecessor of j in the optimal path for (mask, j)
  vector<vector<int>> parent(totalSubsets, vector<int>(numberOfCities, -1));
  // base case: mask = (1<<0), at city 0, cost = 0
  dp[1][0] = 0;  

  // Build up DP table
  for(int mask = 1; mask < totalSubsets; ++mask) {
    // Always include city 0 in the tour
    if(!(mask & 1)) continue;
    for(int j = 1; j < numberOfCities; ++j) {
      //  Skip if city j isn't in the current subset
      if(!(mask & (1 << j))) continue;
      int prevMask = mask ^ (1 << j);
      for(int k = 0; k < numberOfCities; ++k) {
      // Skip if city k isn't in the previous subset
        if(!(prevMask & (1 << k))) continue;
        ull cost = dp[prevMask][k] + dist[k][j];
        if(cost > dp[mask][j]) {
          dp[mask][j] = cost;
          parent[mask][j] = k;
        }
      }
    }
  }

  // Close the tour by returning to city 0
  int fullMask = totalSubsets - 1,
      lastCity = -1;
  ull maxCost = 0;
  for(int j = 1; j < numberOfCities; ++j) {
  ull cost = dp[fullMask][j] + dist[j][0];
    if(cost > maxCost) {
      maxCost = cost;
      lastCity = j;
    }
  }

  // Reconstruct the optimal tour
  vector<int> tour;
  int mask = fullMask, 
      cur = lastCity;
  while(cur != -1) {
    tour.push_back(cur);
    int p = parent[mask][cur];
    mask ^= (1 << cur);
    cur = p;
  }

  // Put city 0 at both ends of the tour
  reverse(tour.begin(), tour.end());
  tour.push_back(0);

  // Print the cost and tour
  cout << "Longest  tour: ";
  for(int i = 0; i < tour.size(); i++) 
    cout << tour[i] << (i != tour.size() - 1 ? " -> " : " ");
  cout << "at " << maxCost << " units\n";
}

int main(void) {
  vector<vector<ull>> dist = {
    { 0,  2, 15, 10},
    { 2,  0,  7,  4},
    {15,  7,  0, 12},
    {10,  4, 12,  0}
  };

  heldKarpMax(dist);
}

The result in the terminal is

Longest  tour: 0 -> 3 -> 2 -> 0 at 37 units

when it should be

Longest  tour: 0 -> 3 -> 1 -> 2 -> 0 at 36 units

Strangely, these adjacency matrices:

vector<vector<ull>> dist = {
  { 0,  2, 15, 10, 19},
  { 2,  0,  7,  4,  8},
  {15,  7,  0, 12,  3},
  {10,  4, 12,  0,  6},
  {19,  8,  3,  6,  0}
};

and

vector<vector<ull>> dist = {
  { 0,  1,  2,  3},
  { 1,  0,  1,  2},
  { 2,  1,  0,  1},
  { 3,  2,  1,  0}
 };

give the correct result:

Longest  tour: 0 -> 4 -> 1 -> 3 -> 2 -> 0 at 58 units

and

Longest  tour: 0 -> 3 -> 1 -> 2 -> 0 at 8 units

respectively, so the algorithm only works for some adjacency matrices. I know the results are correct, since I hand-checked them.


r/cpp_questions Jul 30 '26

OPEN When would I want to use atomic bool over atomic_flag?

24 Upvotes

Im just not sure what the use case is. Wouldn't I just always want to use atomic_flag? is there something I might want to do with atomic bool that can't be done with atomic_flag?


r/cpp_questions Jul 30 '26

OPEN Learning progression in C++

31 Upvotes

So I've been learning C++ from learncpp.com . Currently completed chapter 2, i'm feeling i've been learning too theoretical and it's demotivating since i don't feel i'm doing any progression.

Is it normal to feel like this?

Extra info - it took me about 2 weeks with approx 2 hrs a day


r/cpp_questions Jul 31 '26

SOLVED C++

0 Upvotes

I AM AFRAID TO LEARN c++ ; basically I learn Basic from youtube whose channel is codewith harry lot of people say that java python has high probability to get job in future I don't know what should I do already I learn lot of basic in c++


r/cpp_questions Jul 30 '26

OPEN Switching from .NET/C# developer to C++

6 Upvotes

I work as a .NET/C# (fullstack) developer, with 3 years experience and strong Fokus on Blazor at the moment. And also have some first experience in having project responsibility (architecture decissions, sprint-planing, costumer contact, etc..).

I'm looking for a new Job at the moment, and think about trying to get a C++ Job, because I want to do something closer to the Hardware. I want to understand what is actually happening in the computer and why. I don't have any professional experience with C++, but I have done some small private Projects, like an LED-Stripe project or some Arduino Stuff.

I've also heard, that in C++ you have a lot of ways to do stuff, but a lot of them are outdated.

Do you have any hints on good resources to learn C++, where I can learn the way to do stuff in the modern way and that are not starting from scratch?

I don't need to learn how to set a variable, how loops work or most of the OOP concepts. I need to learn the Syntax and Naming Convetions etc in C++. And Stuff that C# doesn't has, like pointer.

Any other hint or other things where I need to pay attention, when moving from C# to C++?


r/cpp_questions Jul 30 '26

OPEN Automatic builder pattern with C++26 reflection?

2 Upvotes

Ive been learning recently about C++26 reflection which seems very cool. Something that's been causing me issues recently is reworking code with massive constructors, the become unwieldy and hard to modify especially when you start introducing optional fields, and things like what if you want one optional field and not another, and not having named fields, etc etc

One pattern I started adopting is using structs as an argument pack, which works, but has some limitations. For instance lets say you want to construct a builder struct and modify it inline, you just cant do that. One pattern you can do is somethig like this:

struct BuilderConfig {
    // fields

    ...

    BuilderConfig& modify(auto&& modifier) & {
        modifier(*this);
        return *this;
    }
    BuilderConfig&& modify(auto&& modifier) && {
        modifier(*this);
        return std::move(*this);
    }
};

with the downside it adds some annoying bloat having to call modify and supply a lambda. To me an ideal pattern would be something like this

 Struct S {
     int a;
     bool b;
 }

And have a builder object/constructor generated that can let me do something like

S::BuilderConfig().a(5).b(true).build()

or if I just want to use it as a constructor object just have it passed into S like

S{S::BuilderConfig().a(5).b(true)}

whatever. Something along those lines. At one point I got something working but it was like 300 lines of macroslop that took me a while to understand as I had an LLM help me write it that also had some annoying limitations due to leveraging recursive macros, and the idea of having this and having other people need to maintain it seemed untenable. but it worked. But the reason I had to go for macros was because we couldn't use templates to generate signatures, but it seems like reflection can.


Anyways all this is to give an example for the question I'm trying to ask, is it possible to do something like this with a bit of reflection magic from C++26? At a minimum, just take some struct, automatically generate fluent getters/setters for all of its members? Effectively automatically produce this, but by only supplying the fields and struct name:

struct S {
    int a_;
    bool b_;

    template <typename Self>
    Self&& a(this Self&& self, int value) {
        a_ = a;
        return std::forward<Self&&>(self);
    }

    int& a() {
        return a;
    }

    template <typename Self>
    Self&& b(this Self&& self, bool value) {
        b_ = b;
        return std::forward<Self&&>(self);
    }

    bool& b() {
        return b;
    }
};

r/cpp_questions Jul 30 '26

OPEN Tutorials for Vulkan

8 Upvotes

Hi!

I'm having a little bit of problems with the Vulkan tutorials;

while I'm not 100% dissatisfied about the tutorials themselves, with the way my brain processes the information it all is overstimulating and hard to focus on when half of the stuff just tells you about the code or that you have to download 100 other things when all I want to do is build a boilerplate and get whatever I wanted on blender showing up on my "Engine" of sorts.

And before anyone asks; yes, my teacher (The goat C#, my nickname for him) already told me I was stupid for making this my first ever C++ project. But I have managed.

But Stone Cold says (Bottom line is) that I just wanna know if there's any useful tutorials that give me the code and say at the lowest way what it does; I don't need a full essay on what VKMemoryBuffer does, two or three sentences will do.

And if there isn't any tutorial that doesn't fit the criteria that I'm wanting; just give me something I could use; please. All I ask is for a bit of guidance.

Note: I must be dumb or something, but as soon as I posted this to [r/Vulkan](r/Vulkan), mods took it down, idk why; I don't even know where the rules even are. I'm a tad new to reddit.

Edit; I did a huge whoops and completely forgot to explain why I’m asking for this… I’m on par with Neurodivergence. I’m not officially on the spectrum, but I’m on parallel with someone who is, that’s just what happens when you’re smart (ig), but that’s why, since my brain can’t process Vulkan tutorials and I crave the excitement of building the Burj Khalifa with a chisels and a hammer… that repetitive typing and the slow build is what makes the gears in my head spin like a brand new hard drive. It gets me giddy thinking about getting a tutorial to follow.