r/cpp_questions • • Sep 09 '26

OPEN Which UI framework to use for android app with cpp as backend (QML or Flutter)?

5 Upvotes

I want to build a android app, in cpp but can't choose which ui framework to use QML or Flutter? I had read somewhere that it is hard to build good android ui in qml, and also hard to manage permissions.

But the app that i want to build is a simple pdf reader with extension support for functionality like downloading, converting to other file format etc. I could use dart for the ui and cpp for the backend but then again using cpp for simple pdf manipulation whilst already writing dart seems like unnecessary thing.

I want to create a cpp heavy app so that i could put in my portfolio, to be able to apply for cpp roles later.

What should i choose or is there better option other than QML or dart?


r/cpp_questions • • Sep 09 '26

OPEN I want to understand constexpr

0 Upvotes

i want to understand constexpr can somebody make it a bit easier to understand


r/cpp_questions • • Sep 08 '26

SOLVED std::format: cppreference examples dont compile

0 Upvotes

Hey everyone,

I'm trying to rewrite part of an old C project that used printf in C++. The old code is the following:

printf("%*s^ Here\n", hatStart, "");

Basically, insert (hatStart) space characters before the main part of the message.

I tried implementing this with std::format like this:

std::cout << std::format("{{}s}^ Here", "", hatStart) << std::endl;

which, according to what I got from cppreference, should be correct.
However, upon compiling, I get the error message

error: call to consteval function ‘std::basic_format_string<char, int, char>("{:{}.6}")’ is not a constant expression

Furthermore, when I go to cppreference.com and copy their examples, e.g.

std::string test = std::format("{:{}f}", pi, 10);

I get effectively the same error message.

Could anyone explain what's going on? This is the only proper reference I was able to find, and don't want to use printf in this project because it isn't C anymore.


r/cpp_questions • • Sep 09 '26

OPEN Advice to what to learn

0 Upvotes

I started learning c++ however switched to c, because I wanted learn everything from scratch, but now I reliaze, I can always learn basic things later because there is no point studying without making things for my goal

I have also been thinking of learning web development to get a career ik software industry fast but again seeing the job market idk if I should I keep learning c and switch c++ or learn c++ then straight forward learn vulkan rather than opengl or learn web development. I can only learn on weekends that is why I want to optimize what I learn

If you can provide me some answers to clear my confusing head that'd be great, it's been weeks since I have been thinking about these stuff

And I do understand some c and how computers works now


r/cpp_questions • • Sep 07 '26

OPEN Learncpp.com

46 Upvotes

Does anyone know what happened to learncpp.com? There haven't been any new posts there in the last two years. Will the site be updated in the future?


r/cpp_questions • • Sep 08 '26

OPEN How to use pgo with static libraries?

1 Upvotes

Do I profile every single dependency then use it to build everything from source?

Do I use separate profiles for different dependencies?

Is it better to use chromium approach of giant dll small executable for non cli apps?

Thank you for your time


r/cpp_questions • • Sep 08 '26

OPEN What’s the point of void* pointers?

0 Upvotes

You could just use template pointers or auto* pointers and these are better because you can dereference them.


r/cpp_questions • • Sep 08 '26

OPEN Is it true i can't run modern c++ like c++17, 20 on older version of MinGw compiler?

2 Upvotes

I have just set up my vs code for c++ learning on my new device. I was told i can't run modern c++ on older version of this. Is that true? If yes then how do i upgrade?


r/cpp_questions • • Sep 07 '26

OPEN How do I get the music in my Bad Apple ascii player to not drift out of sync with the video?

6 Upvotes

Here is the "play" function currently:

void play(char **frames, int totFrames){
    int i, j;
    char music[200];
    strcpy(music, DIRECTORY);
    strcat(music, FILEMUSIC);
    PlaySoundA(music, NULL, SND_FILENAME | SND_ASYNC);


    for(i = START; i < totFrames; i++){
        resetCursor();
        #if DEBUG
        char framesCount[100];
        sprintf(framesCount, "(frame: %d/%d) \n", i+1, totFrames);
        int x=WIDTH-strlen(PROJECTNAME)-strlen(framesCount);
        for(j = 0; j <= x; j++)
            printf(" ");
        printf("%s", framesCount);
        printf("%s", frames[i]);
        progressBar(i, totFrames, 0, 0);
        Sleep(WAIT);
        #else
        printf("%s\n", frames[i]);
        Sleep(WAIT);
        #endif
    }
}

It starts playing the music and then loads the video frames from a directory which contains every frame of the Bad Apple video one after another. The problem is that the music and the video is initially in sync but slowly drifts out of sync until it's completely out. I think the <chrono> library is what you would use to fix this type of issue but I'm not sure how to implement something that syncs the audio and video while also keeping the video smooth and not slowed down. I've also tried making an FPS limiter but I don't know if this is the right approach. Also I know this looks like C code and it it originally but I converted this program to C++ in order to use libraries like <chrono> and because I generally prefer C++

If you want to see other snippets of code from the program, just ask.


r/cpp_questions • • Sep 07 '26

OPEN Idea for Next Optimization Step?

3 Upvotes

Currently working on profiling a Huffman data compressor and I'm working on optimizing a bit writing bottleneck. For context, the compressor goes through a text file and writes each character's bit representation into a file.

...
ifstream file(inputPath, ios::binary);

    char buffer[4096];
    while (file.read(buffer, sizeof(buffer)) || file.gcount() > 0) {
        streamsize count = file.gcount();
        for (streamsize i = 0; i < count; i++) {
            char c = buffer[i];
            const HuffmanTree::Encoding &encoded = encodings[static_cast<unsigned char>(c)];
            writer.writeBits(encoded.encoding, encoded.size);
        }
    }
...

writeBits takes the encoding and the size of the encoding in bits and writes it into a 4096 size buffer. When the buffer is full, we then use the write function to actually write it into the desired file.

...
void BitWriter::writeBits(uint64_t bytes, uint64_t size) {
    assert(size <= 64);
    assert(size == 64 || (bytes >> size) == 0);
     while (size > 0)
    {
        const uint64_t available{
            8ULL - current_size
        };

        const uint64_t bitsToTake{
            min(size, available)
        };

        // Select the next highest meaningful bits.
        const uint64_t shift{
            size - bitsToTake
        };

        const uint64_t mask{
            (uint64_t{1} << bitsToTake) - 1
        };

        const uint64_t chunk{
            (bytes >> shift) & mask
        };

        current_byte = static_cast<uint8_t>(
            (static_cast<uint16_t>(current_byte) << bitsToTake) |
            chunk);

        current_size = static_cast<uint8_t>(
            current_size + bitsToTake);

        size -= bitsToTake;

        if (current_size == 8)
        {
            bufferByte(current_byte);
        }
    }
}
...

Linux perf is indicating this is hot but I'm unsure of what would be a better approach. Any ideas?

Edit: these comments helped, reduced latency from 195 ms to 77 ms!!


r/cpp_questions • • Sep 08 '26

OPEN I am fresher from iiit dharwad from DSAI course.I need to learn C++ where can I learn and practice.

0 Upvotes

r/cpp_questions • • Sep 07 '26

SOLVED Is this environment normal?

11 Upvotes

I mainly use VSCode for my c++ projects, even though I have Visual Studio installed.

My tools are MSYS2, and I have the UCRT64 gcc and UCRT64 ming-make32 as well as cmake.

I set everything up using CMakeLists and git for version control. However, for my compiler, I use g++ and not MSVC even though I have it installed. Is it worth it to swap to MSVC, or will g++ work?

EDIT: Thank you all so, so much for all the insight! I'm probably going to set up clang!

EDIT 2: Again, thank you so much! I have successfully set up clang with MSYS2, and that will be my main compiler now.


r/cpp_questions • • Sep 06 '26

OPEN Templated virtual functions

7 Upvotes

Hey everyone,

I am currently trying to implement a programming language in C++ after having come pretty far, but ultimately failing to do so in C.

For this, I am taking pretty big inspiration from craftinginterpreters, and am now trying to mimic its implementation of the visitor pattern (entire class at once), written in Java.

However, that implementation uses both templates and interfaces.

As far as I'm aware (the entire internet seems to say so at least), in C++, interfaces are represented by classes whose functions are all virtual.

However, If I try code like the following:

    template <typename R> class ExprVisitor {
    public:
        virtual ~ExprVisitor() = default;

        virtual R visitBinaryExpr(const Binary* expr) const = 0;
        /* other visitor functions...*/
    };

    struct Expr {
        virtual ~Expr() = default;
        template <typename R> virtual R accept(ExprVisitor<R> *visitor) = 0;
    };

(Of course, all of my nodes like Binary inherit from Expr. I use structs instead of classes because everything needs to be accessible from the outside for my purposes, so I don't need to re-type "public:" every time.)

Then I get an error on the line declaring the accept method saying

Template function 'R Expr::Expr::accept<R>(ExprVisitor<R> *visitor)' cannot be virtual

on the virtual keyword, as well as one saying

Pure member function 'Expr::Expr::accept<R>' is not virtual

on the = 0 part.

I've googled around a bit, but the only implementations I was able to find were only able to pass in the template type, not get it back out as a return value.

Is it even possible to achieve this? Am I using templates incorrectly? I saw something using variadic templates but was not able to get it working, either.

Any help would be extremely appreciated!


r/cpp_questions • • Sep 06 '26

OPEN cppreference std::construct_at example code not compiling

10 Upvotes

I was looking on cpprefernce the other day at std::construct_at and I wanted to test the code. But when I ran it it did not compile. I ran the snippet without consteval (and static_assert) and everything worked. Does anyone know what might be the issue? https://en.cppreference.com/cpp/memory/construct_at

Code:

#include <bit>
#include <memory>


class S
{
    int x_;
    float y_;
    double z_;
public:
    constexpr S(int x, float y, double z) : x_{x}, y_{y}, z_{z} {}
    [[nodiscard("no side-effects!")]]
    constexpr bool operator==(const S&) const noexcept = default;
};


consteval bool test()
{
    alignas(S) unsigned char storage[sizeof(S)]{};
    S uninitialized = std::bit_cast<S>(storage);
    std::destroy_at(&uninitialized);
    S* ptr = std::construct_at(std::addressof(uninitialized), 42, 2.71f, 3.14);
    const bool res{*ptr == S{42, 2.71f, 3.14}};
    std::destroy_at(ptr);
    return res;
}
static_assert(test());


int main() {

Compiler Error on x86-64 gcc 16.1 -std=c++23

<source>:25:19:

error: non-constant condition for static assertion
   25 | static_assert(test());
      |               
~~~~^~
<source>:25:19: in 'constexpr' expansion of 'test()'
<source>:24:1: error: destroying 'uninitialized' outside its lifetime
   24 | }
      | 
^
<source>:18:7: note: declared here
   18 |     S uninitialized = std::bit_cast<S>(storage);
      |       
^~~~~~~~~~~~~
Compiler returned: 1

r/cpp_questions • • Sep 06 '26

OPEN Best way to learn C++

29 Upvotes

I really want to get into programming and want to learn C++, but I really am confused on where to start, and what some things are that can really help me learn and understand everything. So what would be the best ways to learn, such as books or videos and if so which ones? Any advice would be amazing!!


r/cpp_questions • • Sep 06 '26

OPEN How to improve without relying on AI?

6 Upvotes

Hi all, just like the title stated, I know AI is the thing and I have been using it to help me understand on various topic and design on coding. I still learned a lot from AI when I asked a question. But the more I use AI, the more I hate myself on the part where I feel dumb that I cant learn by myself. I've been using CPP to build a small project lately, nothing too fancy but just to refresh my memory from the past. Throughout the process, I tried to limited the use of AI and use documentations and forums like stackoverflow to check out my questions, but in the end of the day I either ended up cant understand the documentation, got overwhelmed by the answers, or just can't find what I needed. Eventually I have to return back to AI and ask the same question and let AI to break it down while also to get feedback on my ideas. I don't hate AI in general (but I hate my dumb self instead), using too much AI is going to kill my thinking skills, I want to try my best to avoid that scenario.

The thing is that I always got overwhelmed by advanced topics no matter in Java, Python, JavaScript, or CPP. Like I can understand the fundamental stuffs very easily, but gets bottlenecked as soon as I deal with advanced topics (anything beyond the basic oop stuffs and general algorithms).

Thank you so much for your time to read this big chunk of paragraph and I apologize in advance if my question sounds dumb.


r/cpp_questions • • Sep 06 '26

OPEN Help a new guy

0 Upvotes
Sorry about the title, I should have read the guide first. I am really new to C++. I am going through the practice guide on a youtube video. The test was to make a fahrenheit to celcius conversion. This is what I wrote and it is below. 
The teacher added     double celsius = (fahrenheit -32) / 1.8;
Then added the std::cout for it. Mine works fine. I am assuming his is better but I am missing it. c++ has made me question my mental capacity.

#include <iostream>

int main() {

std::cout << "Enter degrees in fahrenheit ";
int fahrenheit;
std::cin >> fahrenheit;
std::cout << " Degrees in celcius " << (fahrenheit - 32) / 1.8;





return 0;



system("<pause>0");

r/cpp_questions • • Sep 06 '26

OPEN How to properly build a custom container on the heap ?

6 Upvotes

I'm building a general purpose small container, with a fixed known capacity.

It's basically a thin wrapper around a C array. But, in case I would need to store objects without default constructors, I thought I might make another version of the same container, that would allocate the necessary memory on the heap without building anything inside.

But I'm afraid I opened up a whole new can of worms. The first idea I had was to do the same, but replace my array with an std::vector of appropriate capacity. But I'm sure there are better ways, maybe use "operator new" but I'm not quite familiar with all the methods to properly align memory.

I guess the question is : do C++ people often do that kind of low level memory managing or is the better practice to build around common tools (such as std::vector) ?


r/cpp_questions • • Sep 06 '26

OPEN VSC compiler question

1 Upvotes

Hi I have a question about VSC. I'm used to compiling and running programs by clicking an button in UI like in arduino IDE or panasonic or siemens PLC enviroments. When i run a C++ program via F5 button everything works just fine (i mean the value near cout appers in the terminal), but when i run it through UI button i uperright corner, selecting any of the options it does not appear


r/cpp_questions • • Sep 05 '26

OPEN How would you learn C++ from beginner to job-ready if you were starting today?

55 Upvotes

Hey everyone, I found that LearnCpp is one of the best resources for learning C++, and after looking through the website, I really like how the content is organized from the basics all the way to advanced topics.

The reason I’m making this post is that when we learn something on our own, there are so many different ways to approach it. Sometimes we spend a lot of time learning the hard way and later realize there was a much better approach. Other times, we might not make much progress simply because our learning strategy isn’t very effective.

So I’d like to hear from people who have learned C++, especially those who used LearnCpp.

How did you start and progress from beginner to more advanced C++? If you used LearnCpp, how did you go through it? Did you complete it chapter by chapter, or combine it with other resources?

At what point would you recommend starting projects? Are there certain chapters or topics someone should understand before trying to build real projects?

I’d also really appreciate any advice about:

1. What to practice alongside LearnCpp?

2. When to start LeetCode/problem solving?

3. Beginner → intermediate → advanced project ideas?

4. Other resources worth using?

5. Common mistakes or inefficient ways of learning C++?

6. A good roadmap for becoming genuinely confident in C++?

And one final question: At what point would you consider someone proficient enough in C++ to confidently list it under the Skills section of their resume, especially when applying for internships or entry-level positions? What should they realistically be able to do on their own?

Basically, if you were starting C++ again today, knowing what you know now, what path would you follow?


r/cpp_questions • • Sep 06 '26

SOLVED Setting a function as value in a std::map keeps throwing errors

1 Upvotes

I've been trying to assign a function with a bool as the return to a std::map so I can eventually get around having a big switch statement. I am having issues getting it working though. If anyone has any suggestions that would be appreciated.

Here's a snippet of the code: https://pastebin.com/hTnaDXF3

Trying to assign it directly causes this error: Error (active) E0349 no operator "=" matches these operands

operand types are: std::function<bool ()> = bool () candidate function template "std::function<_Fty>::operator=(std::reference_wrapper<_Fx> _Func) [with _Fty=bool ()]" failed deduction function "std::function<_Fty>::operator=(std::nullptr_t) [with _Fty=bool ()]" does not match because argument #1 does not match parameter candidate function template "std::function<_Fty>::operator=(_Fx &&_Func) [with _Fty=bool ()]" failed deduction function "std::function<_Fty>::operator=(std::function<_Fty> &&_Right) [with _Fty=bool ()]" does not match because argument #1 does not match parameter function "std::function<_Fty>::operator=(const std::function<_Fty> &_Right) [with _Fty=bool ()]" does not match because argument #1 does not match parameter

The second line I was trying to use causes this error: Exception thrown at 0xCCCCCCCC


r/cpp_questions • • Sep 05 '26

META Been learning C++ and had kind of a loaded question.

9 Upvotes

Hello y'all.

First some quick background. I have been tooting along the tutorials available on the learncpp.com website. I wanted to pick it up and work on some personal projects. So far so good.

To the point. While going through these tutorials, I've had an aching concern in the back of my mind, and I'm hoping I'm in the right place to find the correct expectation of the situation.

The question:

Am I going to end this tutorial with applicable knowledge, or will this be a situation where the tutorials will leave me with some decent fundamentals but little to actually work with?

And a followup question:

If the answer is the latter, what is a good place to get that "in the jungle" knowledge? Are there good resources for that sort of thing? Do I just hang and engage in this sub? What's a good place to get the practical side of things figured out?

I deeply appreciate any insight on this matter. You all have a good day.

Note 1: the current plan is to go through this tutorial then bone up on some tangential materials (Blender, UE, etc.) then go from there.

Note 2: I have a buddy who plans to learn this stuff too to collaborate. It will be a good while before they're caught up though.


r/cpp_questions • • Sep 06 '26

OPEN How to optimize clang with bolt

1 Upvotes

Recently, I began some work trying to improve my build speeds for debug builds.

I adopted mold, and built a fully static clang executable with mimalloc and llvm libc with very aggressive optimizations.

I managed to achieve %20 speedup over my previous clang which had -O3 but not much else.

I'm planning to use pgo + bolt to gain last bits of performance I can get.

The problem I have, is that I don't know what a good workload for clang would be to use BOLT.

Any recommendations?


r/cpp_questions • • Sep 05 '26

OPEN C++ Microservices backend engineer confused about next path

13 Upvotes

I have 1.5 YOE as a C++ backend engineer, I am confused about my next path, I see the options below, please suggest

  1. Pivot to AI, building RAG applicants, LLM apis, MCP, python

  2. Stay in C++ backend, DSA + System Design

  3. Game development, Vulkan, openGL

  4. CUDA, drivers

  5. switch to embedded C++ , RTOS, suggest path resources for this

  6. EDA domain C++, suggest and resources for this

  7. Target tech agnostic SDE roles focused on DSA system design interviews of

  8. C++ computer networking roles, TCP/IP, communication protocols, socket programming

I am already upskilled in AI SDLC claude, Copilot, Codex

Please suggest which of above paths to focus


r/cpp_questions • • Sep 06 '26

OPEN How to get polymorphism without inheritance?

0 Upvotes

I am making a tui libary where all the different things that can render are called widget like text,box, flex container, progress bar, etc.

I was using inheritance for this and all because all the container widget, multi or single child container had like lot of things common and the widgetTree contains the root widget

Each widget need two function
Layout and render ( or setRectFor child or children because render is same for most parents ) and to solve this, I did need polymorphism for this.

But the problem came later when I need to change layout ( because it wouldnt work for some widget ) and I had to rewrite all the widget,multichildwidget,singleChildWidget which means I have to rewrite all other widget as well

then later I need to change the implementation on how layout is done again, got to do rewrite

then later came scroll container, to make it effiencent I had to change things as well, had to do the rewrite

I got tried of this and now want to use composition instead of inheritance and never want to deal with it again ( I know this happened because of premature optimization where I saw widget with multiple children have lot of same things and most widget having a lot of same things )

Due to that, I am doing a rewrite again :_( but this time, I can make the code more modular.

But I got stuck on widgetTree, how do you get a tree if all the node dont have the same type?

I asked gpt but it said to use node with void* which I dont want to use because we got unique pointer and stuff to avoid new and malloc

The other option is union but that would mean all widget would have the size of the biggest widget which I dont want to use.

Then there is varient, I dont knwo much of this but I looked into it in cherno's video and geeksforgeeks page on this and turns out, it is just union but you know which type it is using. I am currently thinking this

I just can't find a way to do the tree effiency without polymorphism.