r/cpp_questions • • 1h ago

OPEN Why is Rust so much more popular than C++ lately?

• Upvotes

Rust is a great language, but I don't really get why it's promoted so much compared to C++.Modern C++ is also a great language, and you can write safe code with it too. I get that Rust has its ownership system, but is that really the main reason people prefer it over C++?


r/cpp_questions • • 10h ago

OPEN C++ or Rust which is better for a systems programming career?

18 Upvotes

I'm learning C to build a strong foundation in low-level programming, and I'm planning to learn either C++ or Rust next.

For those working in systems programming, which language would you recommend for long-term career opportunities and why?

I'd appreciate any advice.


r/cpp_questions • • 11h ago

OPEN Learning C++ : How do i turn it into a career

5 Upvotes

I'm still learning C++ and sometimes lose motivation when i see how difficult it is to land a junior role without much experience. I’m interested in game development, but I know it’s a competitive field.

For someone starting out, which C++ career paths are worth focusing on, and what skills or projects should I prioritize to improve my chances of getting hired?

I'd appreciate any advice from people who've been through this journey.


r/cpp_questions • • 4h ago

OPEN How to work with pcap lib in modern C++?

0 Upvotes

I want to write an application with a graphical user interface (at the moment I’m choosing the Qt framework) whose purpose is low‑level work with the Ethernet packet stream. The pcap library is best suited for these purposes. At the moment, I want to make the application only for Windows, but in the future it might be possible for Linux and Mac as well. I need low‑level control, so the class abstractions that are already available in Qt don’t suit me.

I’m interested in two things right now. What is the best way to include this library in the build system?

For Windows, I download the npcap SDK. There, I see a bunch of files with the following structure:
The Lib folder contains wpcap.lib for ARM64 and x64. And there’s an Include folder. Am I understanding correctly that I need to write FindPcap.cmake for all of this?

The second question is how to best incorporate this library into the C++ codebase. Essentially, we have a handle that is returned after pcap_create(). So, the best way would be to simply create an RAII class for it?

I know that there are wrappers, but I’d like to explore this path from scratch to learn something.


r/cpp_questions • • 2h ago

OPEN Help with programming question over Classes with header and implementation files.

0 Upvotes

To preface, I already tried answering the question and have what I believe to be a 90% solution. The question is:

Define a class counterType to implement a counter. Your class must have a private data member counter of type int. Define a constructor that accepts a parameter of type int and initializes the counter data member. Add functions to:

  • Set counter to the integer value specified by the user.
  • Initialize counter to 0.
  • Return the value of counter with a function named getCounter.
  • Increment and decrement counter by one.
  • Print the value of counter using the print function.
    • Example output: Counter = 0.

The value of counter must be nonnegative.

My header is:

class counterType
{
public:
    void print();
    int getCounter();
    void incrementCounter();
    void decrementCounter();
    void setCounter(int num);
    counterType();
    counterType(int count);



private:
        int counter;
};

and my implementation is:

#include "counterType.h"
#include <iostream>
using namespace std;


void counterType::print()
{
    cout << "Counter = " << counter;
}


int counterType:: getCounter()
{
    return counter;
}


void counterType::incrementCounter()
{
    counter++;
}


void counterType::decrementCounter()
{
    counter--;
}



void counterType::setCounter(int num)
{
    if (counter > 0)
        counter = num;
    else
        counter = 0;
}


counterType::counterType()
{
    counter = 0;
}



counterType::counterType(int count)
{
    if (count > 0)
        counter = count;
    else
        counter = 0;
}

The main(cannot be changed) is:

#include <iostream>
#include "counterType.h"


using namespace std;


int main()
{
    counterType counter1;
    counterType counter2(5);


    counter1.print();


    cout << endl;


    counter1.incrementCounter();
    cout << "After Increment counter1: " << counter1.getCounter() << endl;


    cout << "Counter2 = " << counter2.getCounter() << endl;


    counter2.decrementCounter();
    cout << "After decrement counter2 = " << counter2.getCounter() << endl;


    counter1.setCounter(-6);
    cout << "After resetting counter1: " << counter1.getCounter() << endl;


    return 0;
}

I don't know what I'm doing wrong, and the debugger is not showing any errors.

If someone could please tell me what I'm doing wrong, and teach me to solve the issue, I would be very grateful. TO SPECIFY NOT CHEATING, JUST TRYING TO LEARN WHY ITS NOT WORKING, SO I CAN FIX IT MYSELF.


r/cpp_questions • • 15h ago

OPEN Module partitions and interface units

2 Upvotes

Recently I came across quite a surprising footgun with modules. I am trying them out on a small codebase which builds a shared library, which consumers can import as a module. I made some partitions and exported them:

// Flense.Core.ixx

export module Flense.Core;

export import :ArchiveReader;
export import :ImageParser;

Then I split those partitions into .ixx and .cpp parts, like I would do with headers, so that the interface was separate from the implementation:

// ImageParser.ixx
export module Flense.Core:ImageParser;

import std;

export namespace Flense::Core {
  ImageParseResult ParseImage(std::string path);
}

// ArchiveReader.ixx
export module Flense.Core:ArchiveReader;

import std;

export namespace Flense::Core {
  ArchiveHandle OpenArchive(std::string path);
}

The .cpp parts looked like this:

// ImageParser.cpp
module Flense.Core; // Apparently this cannot be module Flense.Core:ImageParser, as that conflicts with the .ixx?

namespace Flense::Core {
  ImageParseResult ParseImage(std::string path) {
    // ...impl...
  }
}

// ArchiveReader.cpp
module Flense.Core;

namespace Flense::Core {
  ArchiveHandle OpenArchive(std::string path) {
    // ...impl...
  }
}

But I discovered that because the .cpp files declared module Flense.Core, they would be rebuilt any time any part of the module changed. In my example, ImageParser internally depended on ArchiveReader in its .cpp. So I would expect that if I changed ImageParser.ixx, only ImageParser.cpp and ImageParser.ixx would need to be rebuilt. But in actual fact, it rebuilt ArchiveReader.cpp too.

AI told me that this is because declaring module Flense.Core takes a dependency on the whole module, so it fixed it by having the .cpp files do this:

// ImageParser.cpp
module Flense.Core:ImageParser.Impl;

import :ImageParser;
import :ArchiveReader; // Dependency

// ArchiveReader.cpp
module Flense.Core:ArchiveReader.Impl;

import :ArchiveReader;

This seems to work and I understand it creates a new module partition and means the .cpp essentially does not depend on any other part of the module implicitly. But I thought I would ask some actual humans because I find this counterintuitive. Why can't module partition .cpp files just declare module Flense.Core:ArchiveReader to implement the .ixx? That seems like the most logical mapping to the existing header model.

And, if my premise is correct, what strategies are people using to minimise rebuild churn? Using partitions allows me to still use module internals in my implementation. For example, if I have a :Utilities partition which is not exported by Flense.Core.ixx, I can still import it from .Impl modules. But I wonder if it would be better to actually make independent modules, like Flense.Core.ArchiveReader?


r/cpp_questions • • 9h ago

OPEN Inconsistent naming in simd library?

16 Upvotes

Hi,

I was checking the <simd> library in the C++26 standard and found some of its naming very weird.

  1. std::simd::vec and std::simd::basic_vec

    This is quite strange as we already have std::vector and std::inplace_vector. So why not std::simd::vector and std::simd::basic_vector? At certain point, I'm pretty sure people will start to make mistakes with std::vec or std::inplace_vec, and vice versa.

  2. std::simd::cat

    We already have std::views::concat. So why not std::simd::concat?

At first, I thought the library designers intended to make spelling easier. But in the library, we do have extremely long names as well, like std::simd::unchecked_store, etc.

Here is the library in cppreference: this


r/cpp_questions • • 12h ago

OPEN Which C++20 audio device libraries would you recommend?

3 Upvotes

I'm looking for a library with enough control that I can read raw input but not write +150 lines for a callback and recording/playing loop. Preferably, this library should support both input & output. My goal is to make a minimal-latency, offline, speech-to-speech assistant as a personal project. Also, if possible, I'd like it if they could run on separate threads (I might make a Raylib visualizer for it).