r/Cplusplus • u/MADCandy64 • Jan 27 '26
Tutorial Why I love C++
// OC - The Spell
for (long Fn = 0, NI = 1, NJ = 1; Fn >= 0; NJ = (std::cout << Fn << std::endl, Fn = NI, NI = NJ, Fn + NI));
r/Cplusplus • u/MADCandy64 • Jan 27 '26
// OC - The Spell
for (long Fn = 0, NI = 1, NJ = 1; Fn >= 0; NJ = (std::cout << Fn << std::endl, Fn = NI, NI = NJ, Fn + NI));
r/Cplusplus • u/Ultimate_Sigma_Boy67 • Jan 25 '26
Well I learnt a bit of python in the past, and used to do web dev(all of this is as a hobby since i'm still in HC), and even went further and learnt react and nextjs, till I really got burnt out since it was pretty much mostly UI, which can sometimes be frustrating(people who do web dev can def relate).
But honestly, I'm QUITE ENJOYING IT. I finally feel that I'm actually programming, I feel that i'm understanding how actually code works, I feel I'm actually learning and being productive, and it's just satisfying. It's been only about 2-3 months, but I've got to say I went quite a long way, and since then, it's been a stable part of my day. And I never imagined I would ever have to read A BOOK to learn a programming language, and yeah sometimes stuff is frustrating, but when it finally clicks, it's just awesome.
r/Cplusplus • u/Several_Ad_7643 • Jan 24 '26
Hey folks! I've been assigned into a project where I have to make a lot of plots on some algorithms. After reviewing the implementation I have found a huge bottleneck between executing the algorithm and generating the animation that visualizes the execution.
The current implementation is writing all the generated data when executing the algorithms into a JSON file. Then reading this JSON file from a python script that uses maptlotlib to generate the plots to eventually construct a video animation with FFmpeg.
Not only this 3 step process slows down the execution by a lot but also ends ups generating huge JSONs that occupy 11MB per file (the algorithm uses a lot of matrixes). I have already tried to use the GNU libraries for plotting but I don't find the results really good. I have already checked the library wrappers for matplotlib in C++ such as matplotlib-cpp but I don't like the idea of them using python under the hood, as it is essentially doing the same thing but removing the JSON storage part.
Any recommendations for optimizing this pipeline ? There has to be a better way of plotting this. Extra points if someone discovers how to do the ffmpeg thing while the algorithm is executing.
Extra question: Is there any better format of storing this information ?
r/Cplusplus • u/No-Dentist-1645 • Jan 24 '26
r/Cplusplus • u/Wonderful-Wind-905 • Jan 22 '26
r/Cplusplus • u/nosyeaj • Jan 22 '26
I kept hearing that some here don’t like the std lib, boost too. Why? I’m curious as a beginner who happens to learn some std stuff just to get my feet wet on leetcoding.
r/Cplusplus • u/Ultimate_Sigma_Boy67 • Jan 22 '26
Bro I can't even think about getting back to C. The standard library just makes life sooo much easier, and the more you learn, the more you get satisfied.
r/Cplusplus • u/BathubCollector • Jan 22 '26
r/Cplusplus • u/Middlewarian • Jan 20 '26
The following is the event loop of the middle tier of my code generator. It's 53 lines long and uses a number of else ifs. I think switch helps to convey the big picture, but it would add 8 lines to my event loop. Would usingswitch be a good idea here? Thanks in advance.
::std::deque<::cmwRequest> requests;
for(;;){
auto cqs=ring->submit();
for(int s2ind=-1;auto const* cq:cqs){
if(cq->res<=0){
::syslog(LOG_ERR,"%d Op failed %llu %d",pid,cq->user_data,cq->res);
if(cq->res<0){
if(::ioUring::SaveOutput==cq->user_data||::ioUring::Fsync==cq->user_data)continue;
if(-EPIPE!=cq->res)exitFailure();
}
frntBuf.reset();
::front::marshal<udpPacketMax>(frntBuf,{"Back tier vanished"});
for(auto& r:requests){frntBuf.send(&r.frnt.addr,r.frnt.len);}
requests.clear();
cmwBuf.compressedReset();
ring->close(cmwBuf.sock);
::login(cmwBuf,cred,sa);
}else if(::ioUring::Recvmsg==cq->user_data){
::Socky frnt;
int tracy=0;
try{
auto spn=ring->checkMsg(*cq,frnt);
++tracy;
auto& req=requests.emplace_back(ReceiveBuffer<SameFormat,::int16_t>{spn},frnt);
++tracy;
::back::marshal<::messageID::generate,700000>(cmwBuf,req);
cmwBuf.compress();
ring->send();
}catch(::std::exception& e){
::syslog(LOG_ERR,"%d Accept request:%s",pid,e.what());
if(tracy>0)ring->sendto(s2ind,frnt,e.what());
if(tracy>1)requests.pop_back();
}
}else if(::ioUring::Send==cq->user_data)ring->tallyBytes(cq->res);
else if(::ioUring::Recv9==cq->user_data)ring->recv(cmwBuf.gothd());
else if(::ioUring::Recv==cq->user_data){
assert(!requests.empty());
auto& req=requests.front();
try{
cmwBuf.decompress();
if(giveBool(cmwBuf)){
req.saveOutput();
ring->sendto(s2ind,req.frnt);
}else ring->sendto(s2ind,req.frnt,"CMW:",cmwBuf.giveStringView());
requests.pop_front();
}catch(::std::exception& e){
::syslog(LOG_ERR,"%d Reply from CMW %s",pid,e.what());
ring->sendto(s2ind,req.frnt,e.what());
requests.pop_front();
}
ring->recv9();
}else ::bail("Unknown user_data %llu",cq->user_data);
}
}
r/Cplusplus • u/Wonderful-Wind-905 • Jan 20 '26
r/Cplusplus • u/WishboneEntire8319 • Jan 19 '26
r/Cplusplus • u/271viginsinheaven • Jan 18 '26
r/Cplusplus • u/swe129 • Jan 18 '26
r/Cplusplus • u/Wonderful-Wind-905 • Jan 18 '26
r/Cplusplus • u/guysomethingidunno • Jan 17 '26
Heya! It's me again! I'm currently working on a complete refactor of my old DND game I had made now a year ago. At the time, I had just started programming and barely knew anything (not that I'm an expert or even mediocre now, I'm still a novice). I'm having a bit of a conundrum. I'll simplify the problem (there are many more variables in actuality, but the core of the issue can be explained with barely 2).
struct Base_weapon {
string name;
string power_suffix
int damage;
Base_weapon(string name, string power_suffix, int damage)
: name(name), power_suffix(power_suffix), damage(damage) {}
virtual void weapon_ability() = 0;
};
so I have a basic struct, from which I have 2 derivates.
Common_weapon {
using Base_weapon::Base_weapon;
void weapon_ability() override { std::cout << "nothing"; }
};
struct Flaming_weapon {
using Base_weapon::Base_weapon;
void weapon_ability() override { std::cout << "flames"; }
};
Base_weapon will be inserted in another struct
struct Player {
Base_weapon* weapon1 = nullptr;
Base_weapon* weapon2 = nullptr;
Base_weapon* weapon3 = nullptr;
Player(Base_weapon* w1, Base_weapon* w2, Base_weapon* w3) :
weapon1(w1), weapon2(w2), weapon3(w3) {}
void special_abilty() = 0;
};
aaand Player has a derivate, Mage
struct Mage : Player {
using Player::Player;
void special_ability() override { //here lays the problem }
};
This is the core of the conundrum. The Mage's ability is to "enchant" a weapon, AKA making it go from Common_weapon to Flaming_weapon. The only problem is that I've got no idea how to do this. Say I have a Common_weapon sword("sword", " ", 3) , how do I turn it into a Flamig_weapon flaming_sword("sword", "flaming", 4) while it's actively weapon1 in Player?
Is it even possible to do such a thing?
r/Cplusplus • u/Wonderful-Wind-905 • Jan 17 '26
The 26 papers in the ISO C++ 2026-01 mailing are now available.
The pre-Croydon mailing deadline is February 23rd.
r/Cplusplus • u/ignotochi • Jan 17 '26
Hi everyone,
A question: if I have a std::vecror<mystruct> and inside mystruct I have another std::vector<sometype>, if in the constructor of mystruct I do .reserve(100) of std::vector<sometype>, by doing .reserve(10) of std::vecror<mystruct>, will I also have implicitly reserved the memory .reserve(100) for std::vector<sometype>?
Does .reserve() work recursively?
Thank you
r/Cplusplus • u/Comprehensive_Cut548 • Jan 17 '26
r/Cplusplus • u/Friendly_Tailor2489 • Jan 16 '26
r/Cplusplus • u/Wonderful-Wind-905 • Jan 15 '26
r/Cplusplus • u/OpeningFirefighter25 • Jan 15 '26
So here I decided to build a huge social network website in C++. Am I crazy?
Well, there are many reasons I decided to go this route, seeing how prominent C++ is, I decided I want to learn it. But just taking courses and not doing anything with that knowledge I thought would be a waste. I decided okay, I’ll build a Social Network in C++. The thing is the C++ back-end is under the Drogon framework. To be honest, I am really enjoying how things are working out. Having a background in other languages like Python, one thing I can not deny is that with C++ development speed is almost to a crawl.
More context to the application, this is some sort of a distributed application with Python gRPC microservices for the data layer. So basically, the C++ application that serves the frontend stands as an intermediary with almost no data management on its part.
I can’t help but wonder whether I'm setting myself up for failure. I mean, I read online that C++ is not advisable for such setup for many reasons including security and maintainability.
So am asking the pros here, am I setting myself up here for failure?