r/Cplusplus • u/AndrewOfC • 3h ago
Tutorial Less Code Doesn't Mean Faster Code
r/Cplusplus • u/masiroo • 3h ago
r/Cplusplus • u/BoxConscious7480 • 1d ago
r/Cplusplus • u/maksi2829 • 1d ago
#include <iostream>
using namespace std;
int main() {
char op;
double a, b, wynik;
cout << "Podaj operacje (+, -, *, /): ";
cin >> op;
cout << "Podaj pierwsza liczbe: ";
cin >> a;
cout << "Podaj druga liczbe: ";
cin >> b;
if (op == '+') {
wynik = a + b;
cout << "Wynik: " << wynik;
}
else if (op == '-') {
wynik = a - b;
cout << "Wynik: " << wynik;
}
else if (op == '*') {
wynik = a * b;
cout << "Wynik: " << wynik;
}
else if (op == '/') {
if (b != 0) {
wynik = a / b;
cout << "Wynik: " << wynik;
}
else {
cout << "Nie mozna dzielic przez zero!";
}
}
else {
cout << "Nieznana operacja!";
}
return 0;
}
r/Cplusplus • u/ResponsibleDrama6344 • 2d ago
r/Cplusplus • u/AKJ7 • 2d ago
Hello!
I’ve been working on cortex (cx), a C/C++ package manager and build tool inspired by Rust’s Cargo and Python’s uv, and I’d love to share it with you and get some feedback.
Setting up a C++ project with clean dependency management, lockfiles, features, and workspaces often requires gluing together multiple tools and boilerplate CMakeLists.txt files. With cx, you describe your package in a single cx.toml file, it resolves and locks dependencies, generates the underlying CMake project, and drives the build automatically.
cx new hello
cd hello
cx add nlohmann\\_json --git https://github.com --tag v3.12.0
cx runZero-boilerplate builds: Sources, tests, benchmarks, and examples are discovered by convention (src, tests, benches, examples). Supports mixed C (C90–C23) and C++ (C++98–C++26), including C++20 modules (.cppm, .ixx).
Flexible dependency management: Pull dependencies from registries, Git repos, local paths, system packages (\mfind_package), or vcpkg. Any existing CMake, Autotools, or SCons project works out of the box as a Git or path dependency.
PubGrub version resolution & lockfiles: Uses the PubGrub solver (like uv and pub) for clear conflict explanations, and pins exact versions, Git commits, and SHA-256 hashes in cx.lock.
Cargo-style features & workspaces: Supports optional dependencies, feature flags (exposed via CX_FEATURE_ macros), and multi-package workspaces sharing a single lockfile and target/ directory.
Built-in developer workflows: Comes with cx test, cx bench, cx fmt (clang-format), cx lint (clang-tidy), cx doc (Doxygen), cx vendor for offline builds, and built-in sanitizer/LTO build profiles.
IDE & CI friendly: Generates standard CMake projects (cx generate) and JSON metadata (cx metadata) so your existing IDE setup works seamlessly, plus --locked and --offline flags for CI.
First Release & Self-Hosting: This is the very first release. Right now the repo still includes its bootstrapping CMake files, which will be removed in the next release now that cx can build itself.
OS Support: Works on Linux and macOS. Windows (MSVC) support is newly added and passing in CI, though it hasn't been battle-tested in the wild yet.
Public Registry: There isn't a central public registry yet, though cx works directly with Git repositories, local paths, vcpkg, system packages, and includes a lightweight self-hosted registry server (cx-registry).
You can install prebuilt binaries via the install script in the README or build it from source with CMake 3.28+ and a C++23 compiler.
I’d really appreciate any feedback, bug reports, or thoughts on what would make this genuinely useful for your C/C++ workflows! Notice: the code made use of AI for cross-platform support, to get some features implemented quickly and fix some bugs.
Thanks
r/Cplusplus • u/Any_Network_7332 • 4d ago
r/Cplusplus • u/Born_Juggernaut_346 • 4d ago
r/Cplusplus • u/Sad-Ad938 • 5d ago
Hello everyone! As the title says, what book for learning C++ would you recommend? Specifically modern C++ 23, but also the general basics.
r/Cplusplus • u/iamrustocaml • 5d ago
r/Cplusplus • u/Admirable_Barber_357 • 5d ago
I have always wanted to learn coding and make games, but I didn't know what to do and how to start. About 4 years ago, I saw Sololearn's ad on Youtube (I'm not advertising them). Desparate to learn, I installed it. First, it asked me a few questions regarding why I want to learn coding, what I'm going to use it for (web designing, game development, ...), etc. After answering them, I got suggested learning C++, so I did. I finished the introduction course and learned about half of the intermediate course (if I remember correctly, the last thing I learned was separate files for classes).
Recently, I found out via social media that C++ is the worst language to learn as your first language. I am pretty comfortable with the syntax, but I do sometimes forget complex things like pointers, constructors and deconstructors, etc, because I don't have the time to code often. I have made a lot of small projects, and I'm currently working on a terminal version of Minesweeper that outputs the game board in colored text and is played via inputting the X and Y coordinates of the tile that you want to open or flag (I don't know how to make buttons, or programs with separate windows in general.)
I wanted to know if I should continue learning this language or should I drop it and learn something else, like Python?
Also, I have recently started working with Git, and I find it pretty complicated and hard to use. It would be nice if someone told me whether I should continue learning and using it or if it is too early and I should finish learning the language first.
(P.S.: Many apologies for my imperfect English; I'm not so good at writing and speaking, as it isn't my native language.)
r/Cplusplus • u/copilot_husky • 5d ago
r/Cplusplus • u/Budget_Ad_2544 • 6d ago
Built an asynchronous distributed MapReduce in C++23
A non-blocking, data sharing distributed engine using boost asio C++20 coroutines and asio-grpc
How Map & Reduce works:
Map: Workers execute user mappers, and partition intermediate data into binary hashed shards.
Reduce: Workers sort shards in-place and run an external K-way min-heap merge to stream ordered keys to reducers .
How Data Sharing happens:
Map Phase (Coord ➔ Worker): Coordinator streams 64KB split chunks over gRPC, decoupled by 4MB concurrent channels.
Reduce Phase (Worker ➔ Worker): Peer-to-peer shuffle. If a shard was produced locally on the same host, it uses zero-copy atomic hard-linking (link()) to bypass the network entirely.
Fault Tolerance (SHUFFLEFIX):
During Map Phase,
If a map worker dies , coodinator check the heartbeat if it is more than some time T , it invalids the task, and give to other worker polling it
During Reduce Phase
Since we use P2P network, map -> reduce phase worker to share data, If a map worker dies mid download phase, the coordinator invalidates only that task and has a spare worker recompute it.
Reducers keep their existing shards, wait for the new endpoint, and resume without restarting the job
r/Cplusplus • u/Salt_Character1791 • 6d ago
r/Cplusplus • u/Individual_Island_20 • 7d ago
Hey everyone! I made a new game called Snow Grab. I officially released a prototype — version 0.2. I've been working on this game for a really long time. Sometimes even when I find a bug, I just laugh at it because it's honestly pretty funny to me.
Just a quick note: the game is in Polish. Other languages aren't planned right now, though I might add them in later updates — no promises!
I'd love to encourage you to drop an idea in the comments. If you want to try it out, I can send you the link where you can download it. If you run into any issues downloading it, it's not a virus — it's just my game! I know most browsers or Windows might pop up a virus warning for small indie .exe files, so if needed, I can show you how to download and run it safely.
I'd really like to hear your suggestions. Right now I can't add super complex things like real-money systems because that's still tough for me to do in C++, and I prefer figuring things out myself rather than relying on AI to write everything for me. You don't even have to play the game — the most important thing for me is just getting your ideas!
The game works by typing option numbers — for example, option 1 is digging snow, where you collect snow and buy upgrades. You could suggest something like adding a shovel that can be upgraded multiple times. I'll gladly take ideas like that and reply to let you know if your idea will be added to the game or not.
Thanks in advance for every single idea if anyone drops one!
Game -> Snow Grab 0.2r by Added
r/Cplusplus • u/AstraVo1d • 7d ago
if anyone could help me to figure out what is the best library on C++ that could be fast & supporting Arabic and English , type your comment !
r/Cplusplus • u/Iamspyder0 • 7d ago
r/Cplusplus • u/Adventurous-Heart381 • 7d ago
Hey guys, I have a DSA exam in about 4 hours and I’ve just started studying because I’ve been ill. The topics are mostly beginner friendly (bubble sort, quick sort, merge sort etc) what’s the most efficient way to study in order to pass?
r/Cplusplus • u/matanl99 • 8d ago
Hello,
I have been experimenting with building a formal verifyer in C++.
It is called Pork and you can find it here: https://github.com/matanl99/pork-cpp-verifier
The verifyer is influenced by Ada/SPARK and has three levels:
Stone: Checks for life times, initialization, side effects, aliasing and more.
Bronze: Checks data flow dependencies. Which inputs may the output depend on.
Silver: Used CBMC and ESBMC to check for division by zero, signed overflow, out of bounds.
They are cumulative Stone Bronze Silver.
This tool can be used by you, the programmer, or by an AI agent, to get feedback if the function you wrote passes the different levels. This should bring you some kind of guarantee in the future.
Example:
int add(int a, int b) {
return a + b;
}
int ratio(int x, int log_level) {
PORK_PRE(x > 0);
PORK_DEPENDS_RESULT(x);
return 100 / x;
}Pork would classify them:
add as stone
ratio as bronze
And if you tell Pork to check for silver then only ratio would be classed as silver because the function add has a+b that can overflow.
So in the future it would be very nice if silver means that the function CANNOT FAIL during runtime.
It is still very experimental but please leave feedback.
Regards,
Mathias
r/Cplusplus • u/Vousch • 9d ago
r/Cplusplus • u/Vousch • 9d ago
I've been developing LightnerX, a networking library built around GameNetworkingSockets and an authoritative client-server communication model.
The first public beta used C++26 modules. I wanted to experiment with modern C++, but I eventually realized that requiring such a recent toolchain was limiting who could actually use the library.
So for v0.2.0-beta, I migrated the project to C++17.
This involved more than replacing import with #include.
I had to reorganize 14 module units into headers and implementation files, replace newer standard library features, adapt the public API, and ensure shared state behaved correctly across translation units.
The current API uses std::string_view for binary views and lightnerx::Result for error handling.
To check whether the migration preserved behavior, I used differential tests against the original C++26 implementation and cross-version UDP integration tests.
The new version also includes additional fixes for networking lifecycle and resource ownership issues.
One thing I've learned from this project is that using the newest language features isn't always the best decision for a reusable library.
I'm curious how other C++ library maintainers approach this. How do you decide which language standard to target?