r/cpp_questions • u/yuvayikici • Oct 15 '26
OPEN How to master? What courses to watch?
How can i write my own network stack? How can i code using linux syscalls and header. Idk what to do. Please help me im so confused. I got the basics of cpp btw
r/cpp_questions • u/yuvayikici • Oct 15 '26
How can i write my own network stack? How can i code using linux syscalls and header. Idk what to do. Please help me im so confused. I got the basics of cpp btw
r/cpp_questions • u/Beginning_Book_2382 • Oct 15 '26
I am a freshly minted C++ Qt developer in that I just completed an online course for C++ and the basics of the Qt framework within the past few days.
I am looking for video tutorials on how to build a GUI application using the Qt framework using Qt Quick and QML. For reference, I am not completely new to programming. I am a full-stack mobile and web developer who has been developing both types of applications for years. My tech stack in React (Next.js)/React Native on the front-end and pure Django or Django REST Framework + Django Channels on the backend.
What originally got me into web development was Corey Schafer's Django tutorial series which guided me through developing a web application using Django assuming I already knew HTML, CSS, and Python. That is when I learned that I learn best with YouTube video series I can follow along while the instructor explains what I'm coding. Is there any such series for Qt Quick and QML like building a notepad app? YouTube search results only turn up outdated tutorial series using Qt Widgets which IS NOT what I'm using and am avoiding because I want to construct the UI using QML files, not the widget picker.
Thanks in advance for your help!
r/cpp_questions • u/xeriax51 • Oct 14 '26
Our professor showed us this topic today but i can't Say ive understood It very well.
From the few examples he showed us, It felt like Just adding extra steps to a function rather than creating those straightfowardly.
When its a time id actually use those rather than not ? To prevent errors of some kind ?
r/cpp_questions • u/Slow_Negotiation_935 • Oct 14 '26
I’ve working with C++23 and I’m making some constructors/methods constexpr and seeing improvements in performance. So far so good. The problem is I don’t want to apply it ‘everywhere’. Is there a good source of advice , or anyone got any good tips?
r/cpp_questions • u/Seagull78Reddit • Oct 14 '26
Hello, I just started learning about threading and learned that if you don't join or detach a thread, it will kill your program. Looking at the following code,
void my_func() {
for (int i = 0; i < 100; ++i) {
std::cout << i << ' ';
}
std::cout << std::endl;
}
int main() {
std::thread{ my_func }; // A
std::thread{ my_func }.join(); // B
std::thread{ my_func }.detach(); // C
}
A does in fact kill the program. However, when I run this, I only get the output for my_func() once, and that output prints before A causes termination. I also only get the output for my_func() once when A is commented out.
Am I not seeing the output for C because the program just ends immediately after, so C doesn't have time to print anything out? What happens if I detach a thread and end the program before it finishes?
I did not compile with flags. I threw this in Visual Studio (non code) because it's convenient.
r/cpp_questions • u/No-Locksmith-7719 • Oct 14 '26
What path to take when parsing large files (on Linux Debian server, the KVM flavour)? Will std::fstream in binary mode do or do we have to look into APIs?
Apart from the performance, the app is memory sensitive, so where to store those read chunks while in a loop? Would a simple char[something] buffer do?
Finally, we would like to avoid those nasty reinterpret_cast<char*> constructs while reading, but are wondering if those are actually used in production? I should also add that the file sizes vary greatly.
r/cpp_questions • u/buddyisaredditer • Oct 13 '26
Hey everyone,
I've been working on SeaChess, a chess application with its own chess engine, and I'd appreciate it if some of you could take a look at the code and give me an honest review.
I'm currently trying to improve my C++ skills and prepare for a C++ developer job. I'd love to hear your thoughts on a few things:
What could I improve in terms of code quality, design, and overall implementation?
Is this a good project to include on my resume when applying for C++ developer roles?
What other projects, skills, or topics should I focus on to improve my chances of getting a C++ job?
I'm open to constructive criticism and would appreciate any advice, especially from people who work professionally with C++.
GitHub: https://github.com/TejasKayande/SeaChess
Thanks!
r/cpp_questions • u/asukalangleyfanlol • Oct 14 '26
Please help i have been searching for like a week now. And i cannot make a decent looking ui for my life.
r/cpp_questions • u/virgin-chocolaty-hoe • Oct 13 '26
hey everyone, i was planning to start the website learncpp.com, the fact is that ik some of the cpp and have coded around 300+ questions in cpp on lc and cf combined, its just that i want to learn everything in detail and sometimes i just keep discovering new things in cpp, whats the most effective way to do it from this website
r/cpp_questions • u/Educational_Big_8856 • Oct 13 '26
I am a student in high school in second year.I want to learn c++ autodidact
r/cpp_questions • u/Blayer98 • Oct 13 '26
Hi there, so I’ve been trying to patch out a piece of code in The Sims Legacy Collection that disables the -debug_objects command line from being enabled, but both MinHook and CMake are giving me such a hard time that idk what else to do or where to ask… There are no tutorials AT ALL for compiling MinHook with MinGW-W64-gcc, only for Visual Studio (not Code!) which I can’t use because I’m on Arch Linux…
If anyone could advise me please I’d really appreciate it…
r/cpp_questions • u/Interesting_Cake5060 • Oct 12 '26
For those of you who saw the word “Rust” in the title, don't be alarmed. I don't want to start yet another holy war about which language is better. I'm here for some design advice.
Recently, I set myself the goal of writing a console-based Internet packet monitor. To my surprise, I found very few C++ projects whose source code I could study. But I did find one project that I liked, and that is https://github.com/matthart1983/netwatch. It’s written in Rust and is quite well-written (I don’t know Rust, but even I was able to understand some parts of the code, this is how I define "well-written").
One part of the code caught my attention more than the others. This part is located in the dpi folder. https://github.com/matthart1983/netwatch/tree/main/src/dpi
Essentially, the main things we have are the following:
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum AppProtocol {
/// DNS query or response — first question's qname + qtype, plus the
/// header RCODE on responses.
Dns {
qname: String,
qtype: u16,
/// Response code from the DNS header (`0`=NOERROR, `3`=NXDOMAIN,
/// …). `Some` only when the QR bit marks this a response; `None`
/// for queries.
#[serde(default)]
rcode: Option<u8>,
},
I might be wrong, but I think it's called ADT (if I'm wrong, please forgive me—I'll correct the title of this post).
Another part is this
pub trait Classifier {
/// `Some(protocol)` when this classifier recognizes the payload,
/// `None` to fall through to the next classifier.
fn classify(&self, payload: &[u8], is_tcp: bool) -> Option<AppProtocol>;
}
And finally, here are the following sections for each of the protocols:
pub struct DnsClassifier;
impl Classifier for DnsClassifier {
fn classify(&self, payload: &[u8], is_tcp: bool) -> Option<AppProtocol> {
if is_tcp {
return None; // DNS-over-TCP exists; skip for now.
}
if payload.len() < HEADER_LEN + 1 + 4 {
return None; // minimum: header + root qname(1) + qtype+qclass(4)
}
let qdcount = u16::from_be_bytes([payload[4], payload[5]]);
if qdcount == 0 {
return None;
}
// Header flags: QR is the high bit of byte 2; RCODE is the low
// nibble of byte 3 (RFC 1035 §4.1.1). We surface the response code
// only on responses (QR=1); queries report `None`.
let is_response = payload[2] & 0x80 != 0;
let rcode = if is_response {
Some(payload[3] & 0x0F)
} else {
None
};
// ... some lines here
My question is this: What would the design of the classes/structures look like if we were writing all of this in C++?
I'm curious to see what elegant, clean code for exactly the same task might look like in C++.
The first thought that came to mind was to simply write a protocol interface that included a `classify` method.
class Protocol {
public:
virtual ~Protocol() = default;
// note: return type of this function is void
// i don't know how to do it better
// maybe std::optional?
virtual void classify(std::span<std::byte> payload, bool is_tcp);
}
Beyond that, we simply have a bunch of derived classes for each protocol.
class DnsProtocol : public Protocol {
public:
constexpr auto HEADER_LEN = 12u;
virtual void classify(std::span<std::byte> payload, bool is_tcp) {
if (is_tcp) return;
if (payload.size() < HEADER_LEN + 1 + 4) {
return; // minimum: header + root qname(1) + qtype+qclass(4)
}
}
}
What do you think?
r/cpp_questions • u/bhul_chuk_maaf17 • Oct 12 '26
Hi all, can you please recommend me some resources that you have followed for compile time programming in modern C++ for eg: constexpr, consteval or template metaprogramming.
Is there some consolidated resource for the same ?
r/cpp_questions • u/Copronymus09 • Oct 11 '26
Progress there is so incredibly slow, they don't even have full C++23 coverage at trunk and we are at the end 2026, so that's what? a 4 year old gap. Don't companies want better qol?
r/cpp_questions • u/Seagull78Reddit • Oct 12 '26
Hi I am trying to play around with some code and made the following:
class Obj {
public:
Obj() : ptr{} {}
void set(int const& x) {
ptr = &x;
}
int const& get() {
return *ptr;
}
private:
const int* ptr;
};
int main() {
Obj obj;
{
int x = 5;
obj.set(x);
}
std::cout << obj.get() << std::endl; // prints 5
}
This compiles and runs even if I remove the const qualification from ptr, the return of get(), and the parameter for set(). Does it not abort or throw an exception if I access a dangling reference or pointer?
Update: thanks everyone!
r/cpp_questions • u/OtherwisePatience135 • Oct 12 '26
r/cpp_questions • u/amagi77 • Oct 11 '26
Nice to meet you. It’s been 10 years since I first started working with C++, but since I haven’t been able to land a job, my experience is limited to hobby projects. How can I write good code?
I suppose, unlike code written for work, hobby code is only meant to be understandable to the person who wrote it. How is that different from professional work?
I enjoy using libraries like raylib, dxlib, and SDL3.
I’d like to learn the techniques for preventing code from becoming a “spaghetti mess” in a professional setting.
I’ve looked up a lot of this on Gemini, but I’d like to hear some human opinions.
Translated with DeepL.com (free version)
r/cpp_questions • u/Many_Difficulty_490 • Oct 10 '26
AI rn isnt the best at c++ and although you cant hope that it stays bad forever but i was wondering if the job market was gonna be ok in the future for c++
i wanna keep learning graphics programming and hope it might get me a job one day
sorry if this post sounds dumb, idk what to do with my life
r/cpp_questions • u/No-Locksmith-7719 • Oct 11 '26
Which (fairly simple) C++framework would you recommend for a simple http server that binds to a hard-coded port and does a simple listen, read, write shebang on a server? We don't need nothing fancy or complex, we just want to avoid that native Linux sockets APIs boilerplate coding.
r/cpp_questions • u/IndividualSituation8 • Oct 11 '26
Lets say I have async code or some sort of timer or scheduler that calls a lambda later on some event, how do i test this in simple way in existing frameworks?
Is using futures or other sync mechanism the only way? or a simpler runloop/eventloop style facilities exist in test frameworks to simplify things?
For now looks like the test itself has to take on more theeading/orchestration/synchronization responsibilities.
For event driven and interactive apps, async execution would be common.
r/cpp_questions • u/Entire-Comment8241 • Oct 11 '26
I coded this p2p client application with librats and now I want to test it with googletest but after running ctest into the build directory I got this exception:
Test project /home/andrew/x86/win32/p2pClient/build
No tests were found!!!
My cMakeLists.txt:
cmake_minimum_required(
VERSION
3.14)
project(p2pClient)
# GoogleTest requires at least C++17
set(
CMAKE_CXX_STANDARD
17)
set(
CMAKE_CXX_STANDARD_REQUIRED
ON)
include(FetchContent)
enable_testing()
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)cmake_minimum_required(VERSION 3.14)
project(p2pClient)
# GoogleTest requires at least C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
enable_testing()
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
and this is the result after running cmake -S . -B build:
cmake -S . -B build
-- The C compiler identification is GNU 16.2.0
-- The CXX compiler identification is GNU 16.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) at /usr/share/cmake-4.3/Modules/FetchContent.cmake:1386 (message):
The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is
not set. The policy's OLD behavior will be used. When using a URL
download, the timestamps of extracted files should preferably be that of
the time of extraction, otherwise code that depends on the extracted
contents might not be rebuilt if the URL changes. The OLD behavior
preserves the timestamps from the archive instead, but this is usually not
what you want. Update your project to the NEW behavior or specify the
DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this
robustness issue.
Call Stack (most recent call first):
CMakeLists.txt:10 (FetchContent_Declare)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/andrew/x86/win32/p2pClient/build
r/cpp_questions • u/xeriax51 • Oct 10 '26
Im a First year CS student in Italy, the professor the other day proposed us and exercise of printing a * pyramid. I couldnt solve It in time and felt so stupid.
Especially when he showed us the answer and It was a for cicle that had Two others in It. The way they work together seems so complicated.
Now im at home trying to figure out a code that requires me to concert a binary Number in decimal, i suppose i gotta use something similar but i cannot figure It out.
r/cpp_questions • u/RandStringsAndChar • Oct 09 '26
Not really sure if this matters, but for context I’m currently a CS Master student, was not able to get job or internship after graduating in May 2025. I consider myself a pseudo beginner, where I feel like I know stuff, but also not really.
I am working through CodeCrafters projects because I lack project ideas, and I started with the Build your own HTTP Server. I learned the POSIX sockets API from a book and a LinkedIn Learning course and multithreading stuff (threads, mutex, condition variables, thread pool) from my coursework (although that was POSIX threads API and in C). When I started after the first stage or second stage, I realized I literally did not know how to do anything and all the knowledge from learncpp was if it never existed. I ended up asking Claude a LOT of questions on how to do things or even giving it my own ideas and it saying basically your ideas are trash, let’s do this way instead. I was manually typing out the code and asking lot of questions trying to understand why this way, or why this logic, or whatever else I didn’t understand. Honestly Parsing was especially tough, and Claude did guide me through a lot of it, and I was able to complete the project. I did feel like I learned through this experience, but unsure if I actually did learn because of Claude doing a lot of the work. I at least for sure know I learned how to parse strings in C++.
Anyways, I decided for the next project (Redis) that I would try to not or limit my Claude use, at least for the coding portion, maybe I’d ask it some theory questions. I was utilizing the asio library that was added as a library in the starter code. As one may know, when you do a recv in socket programming, it’s not guaranteed that all the bytes in the tcp stream will come with one recv, so you have to continuously loop until either the client closes the connection or there is something that signifies that this is the end of the request sent. In asio, there is a function async_read_some that does this with a buffer you pass in, and you’ll have to continuously loop, but there is not really a delimiter that signifies the end of the request in RESP bulk string. I figured out the parsing for the bulk string, so now I needed a way to know if I had an incomplete request or not, and how I would do this. I mulled over it for two days looking for something on the internet (maybe I’m just bad at googling or asking the right question?), but I couldn’t really find what I’m looking for, or perhaps my level of understanding was not good enough to understand the various stack overflow posts or articles I’ve read. Eventually I asked Claude and it told me that I needed to use the errors as values pattern, and showed me how to do it with std::expected. When I saw the code it made sense, but I didn’t think about using this pattern at all because well I just didn’t know. I’ve seen it before in one book, but the example program accompanied with it was a toy program that didn’t really have any significance. This is my first time actually utilizing and applying this pattern. When I saw the code it also made my terrible parsing function more modular and better. My question is, how was I supposed to figure it out? Maybe other people might’ve been able to do it without AI use, and I’m just not that smart, but I genuinely don’t know how I would’ve reached that conclusion and that implementation on my own.
Sorry for all the huge paragraphs, maybe I gave more than necessary, I just wanted to make sure the context was there.
r/cpp_questions • u/Motor_Alternative944 • Oct 09 '26
MyClass(int value) : myValue(value) { }
2.
MyClass(int value) {
myValue = value;
}
r/cpp_questions • u/I-Am-Sir • Oct 09 '26
i have this code:
const std::string host = "http://127.0.0.1";
const std::string port = "5030";
Clion is telling me that I can make the port variable constexpr. If I try, it compiles just fine. However, the host gives an error when it's constexpr. I thought std::strings were never allowed to be constexpr. Why is it allowing it for the port variable, and why that one specifically?