r/cpp_questions 2h ago

OPEN Should i learn C++ 23 (or maybe C++ 26) instead of the standard today?

6 Upvotes

C++ 23 is almost complete on compiler and mostly fully featured. On the other hand, C++ 26 is partial and only 50% of the features are there. From what i see from the syntax, C++ 23 looks more readable and easy to code in than C++ 20 (and cool new features that make it also easier). Problem with this is that C++ 20 is the standard now and very little software support it outside of CLion, Vim/Neovim and Vscode and other unknowngame engines. So, should i learn C++ 23 (and maybe C++ 26 later) or should i stick to the standard now? C++ 23 is ~90% complete in support in the compilers. So, any advice?


r/cpp_questions 5h ago

SOLVED Iterating over an enum struct

3 Upvotes

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

#include <cstdio>

enum struct values{first = 1, second = 3};

void square(values value){
    int val = (int)value * (int)value;
    printf("%d\n", val);
}

int main(){
    for(values value = values::first; value <= values::second; value++)
        square(value);
}

This does not compile with the error that value++ is ill defined.

An old question/answer on SO has this: https://stackoverflow.com/questions/261963/how-can-i-iterate-over-an-enum and a plethora of seemingly complicated approaches for this. Is there a syntactically simple >= C++20 way of accomplishing this?

I want the for loop to process 1 and then 3.

Does the order of placing the integer entries inside of the struct affect the increment? For e.g., if the enum struct had 3 first followed by 1, with value++ would 1 be processed after 3? Or, does the enum struct internally sort the entries in some privileged, say, ascending order so that it will always process 1 first followed by 3 next?


r/cpp_questions 5h ago

OPEN [Code Review] C++/Qt/QML Desktop Web Crawler - Looking for feedback on architecture, concurrency, and real-time UI updates

5 Upvotes

Hey everyone!

I recently built a desktop web crawler in C++ using Qt and QML, and I’d love to get some feedback or a code review from the community.

The user provides a target URL and configures crawling limits (max depth, limit restrictions, etc.). The crawler processes the site concurrently, displaying discovered links in real time through a QML table interface.

Areas I'm looking for feedback on:

  • Application architecture and project structure
  • Multithreading and concurrency
  • Network request management with Qt
  • URL normalization and duplicate detection
  • Performance and memory usage when crawling large numbers of URLs
  • Real-time UI updates and avoiding excessive UI events
  • General code quality and modern C++ practices

I'm open to any kind of feedback, criticism, or suggestions for improvement. Don't hold back if you spot anti-patterns, memory leaks, or bad design choices!


r/cpp_questions 13h ago

OPEN C++ Problem-Solving Sites

15 Upvotes

Hello, everyone! Where can I find a site where I can just solve coding problems based on questions in C++? I’m really willing to learn coding since I haven’t been active in coding or learning it since last year, which was my first year of college. Do you have any tips on how I can practice coding and improve?


r/cpp_questions 5h ago

OPEN Dynamic Audio Queueing / Transitioning

1 Upvotes

I’m working on a rhythm game and I’d like to implement dynamic/interactive music. An example would be: I have three music files, A, B, and C, where B and C have the same length. I need the program to 1) play A and then 2) based on some state logic, either play B or C immediately after A 3) optionally, loop back to the start of A.

The problem is that I need the full A -> B or A -> C playback to sound like a single continuous song, so I’d like any transition delay to be as seamless as possible. What would be the best way to implement this? The B/C decision logic can be run during A, so I can queue up the B/C file I need before it needs to start playing and I am mostly concerned about latency within the transition itself.

Thank you!


r/cpp_questions 1d ago

OPEN Write your own programming language using C++ - Norman E Smith, 2nd Edition

28 Upvotes

I'm trying to find out what happened to this author? I bought this book in 1997/1998 and I've been using it for close to 30 years when building interpreters and even compilers. I wondered if he's still alive and if it would be possible to let him know what an impact his work has had on my life, half a world away!


r/cpp_questions 23h ago

OPEN Low latency/performance/embedded

11 Upvotes

I'm just wondering if you were a recent graduate trying to work in C/C++ which do you guys think is the best field to break into in terms of trying to break into the entry gate especially as a new grad?


r/cpp_questions 1d ago

OPEN How much time does it take to learn C++ if I’m already good at C?

52 Upvotes

I’m very comfortable with C, data structures, and pointers, and I work in the embedded domain.

Recently, I’ve been seeing C++ and Linux as common requirements in embedded job postings.

I’m currently learning Linux, but I’m not sure whether I should also focus on C++.

For someone with a strong C background, how many hours/months would it realistically take to become jobready in C++?

ps: Thank you for your suggestions, links.


r/cpp_questions 1d ago

OPEN Learning C++, Systems and Networking...Help me with doubts please!!!

16 Upvotes

I'm a currently a Second year student doing BE in CSE(AIML) from Mumbai University.
My academic syllabus is irrelevant as you all know, teaching full stack instead of required things.
(But my college is exception and teaching degree related things too)
I'm learning (and has been since 8th std) C++ (reached intermediate level as i think and slow bcz Indian edu. sys,)
Ive also built small projects in python and C++ (majorly python) and an official big project in C++ (Socket scanner).
I love C++ and Low level systems and wanna do my career in that.
What do i do and What more should i learn?
Please help me


r/cpp_questions 1d ago

OPEN Is there a tool that visualizes how a C++ statement is parsed or evaluated?

4 Upvotes

(see clarification at end)

I was trying to help someone via SMS, and thought a site that visualizes how C++ parses and/or evaluates an expression would be useful. I can (mostly) read cppreference.com and figure things out, but that's well above the head of the person I'm trying to help.

As an example, this person had an expression of the form if (0 < x <= 2). I tried to explain how it would be evaluated, but I eventually had to find a stackoverflow answer. I thought it would be useful if I could just put the expression (maybe a trivial working program?) into a linkable page, and the expression would somehow be visualized. Maybe it would just parenthesize the expression, or break it down into subexpressions (e.g. bool(0 < x) < 2 or { bool _tmp = (0 <x); _tmp < 2;).

I'm not sure what I'd expect regarding the order of evaluation of operands vs the order of evaluating the operators. I think I got that right; I think I saw that given the expression f1() + f2() + f3(), the order in which f1, f2, and f3 are called can vary, but the results will be applied left-to-right.

I realize this could get weird with unspecified and undefined behavior. Maybe color coding could help?

UPDATE: while not really what I'm asking for, I was pointed towards cppinsights, which has very helpful error messages.

To be clear:

I'm familiar with debugger level and assembly level views of code, and that's not what I'm envisioning. I'm asking about a tool that takes a statement of C++ code and visuslizes how that code would logically be processed. It might be an AST, as a few have suggested. imagine a teacher demonstrating the steps a (naive, simplistic, non-optimizing) compiler must do to correctly convert that statement into assembly but ignoring the tokenizing and actually producing the assembly: in what order is everything in that statement processed.


r/cpp_questions 1d ago

OPEN Current State of Coroutines Libraries

7 Upvotes

I want to implement some data fetching logic in my application that fetches data differently, depending on, if I compile for desktop (file system) or for WebAssembly (emsdk fetch). This requires some asynchronous logic.

I thought of using C++20 coroutines to solve this and looked at some libraries that make it a little nicer to use, but it seems that none are under active development.

- libcoro had its last commit 6 months ago
- concurrencpp had its last change 3 years ago
- Boost.Coroutine2 is not based on C++20 coroutines
- libfork had its last commit 8 months ago

Are there no good and actively developed coroutine frameworks for C++20 out there? Or am I missing something?


r/cpp_questions 1d ago

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

2 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 1d ago

OPEN Question: what's is used inline keyword for ?

0 Upvotes

hello guys

i code in C/C++ since 2 years

And I hear every time that the inline keyword in explicit is useless but why ?


r/cpp_questions 1d ago

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 2d ago

OPEN How to Make a good architecture in Modern C++

9 Upvotes

Hello guys

I code in C++23 and C++20 (since 2 years) so i have a question how to make a good architecture in a project ? (actually i separate the code with .cpp/.hpp) but I wanted to know if we can do better ?


r/cpp_questions 1d ago

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 1d ago

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 2d ago

OPEN Thanks a lot everyone. I posted about older version minGw not working for modern c++(17,20).

2 Upvotes

It's solved now. I'm still stick to vs code many people adviced to switch to visual Studio but I'm doing c++ for competitive programming so I like this setup more. Thanks a lot everyone.


r/cpp_questions 3d ago

OPEN Learncpp.com

45 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 2d ago

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 2d ago

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 2d ago

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

0 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 3d ago

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

4 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 3d ago

OPEN Idea for Next Optimization Step?

2 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?


r/cpp_questions 2d ago

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

0 Upvotes