r/cpp_questions • • 6h ago

OPEN For those that work with C++ in their jobs; how has AI affected your work?

27 Upvotes

Hello,

I am someone who is really passionate about programming. I dont really care as much about the business side of things in SWE - i just love problem solving and programming is one way for me to express that, kind of like writing a mathematical proof

C++ is one of my biggest passions in programming. I love the language and everything about it. Sometimes if im bored, i read a cppreference page about something I am unfamiliar about, so I have grown somewhat attached to the language

I was so excited to put my passion for C++ to use at a job. Thankfully, I managed to land a (C++) internship and completed it this summer; I had barely used any AI, but still managed to keep up and receive a return offer, so I will be starting as a graduate next year. After completing the internship I had alot of hope that Id be able to do my job the way i want to and not have to use much AI (because at the time, id say most of the good C++ devs still didnt rely on AI much)

Ofcourse since then there have been advancements in the models, so I dont know what the current state of my future workplace is

What is your guys' experience? Is everyone using AI to write the code for them? How do you guys maintain your skillset if youre not writing the code yourself? Whats your outlook on the future of the C++ industry? Are people like me just going to have to suck it up and keep C++ as a hobby?


r/cpp_questions • • 8h ago

OPEN Cpp books

13 Upvotes

Hi I'm a first year from a tier 3 university. I want to learn about cpp i have basic knowledge about C++

Inheritance, getters and setters etc I'm also learning data structures and algorithms. I want to improve my cpp knowledge, what books you guys recommend . I personally thought about going for The C++ Programming Language by Bharne Stroustrup. What are some of the better books than this I'm also targeting quant as of now but as a backup I'm keeping software engineering.


r/cpp_questions • • 13h ago

OPEN Rate my code.

0 Upvotes

I´m new at programing, I just download code::block today to start learning c++ and I got obsessed.

Here is an excersise I´ve done, and im really proud of:

#include <iostream>
using namespace std;

int precio = 80;
int desn = -30;  //desn es el descuento para niños
int desam = -35; // desam = descuento adultos mayores

int edad;

int cliente = 0;
int mayor = 0;
int menor = 0;

int recaudomenor = 50;
int recaudomayor = 45;
int recaudo = 80;

int main(){

  cout << "Bienvenido al cine. El precio del boleto regular es de $80, pero tal vez pueda obtener un descuento." << endl;

  cout << "Por favor, ingrese su edad: ";
  cin >> edad;

  while (edad != -137){

  if (edad < 12) {
  precio += desn;
  menor = menor+1;
  cout << "Felicidades, niño, tienes un descuento." << endl;
  }

  else if (edad >= 60) {
  precio += desam;
  mayor = mayor+1;
  cout << "Enhorabuena, usted tiene un descuento." << endl;
  }

  else {
  cout << "Disfrute la función, es lo único que puede." << endl;
  }

  cout << "Su total a pagar es de: $" << precio << "." << endl;

  precio = 80;
  cliente +=1;

  cout << "\n\n\n\nBienvenido al cine. El precio del boleto regular es de $80, pero tal vez pueda obtener un descuento." << endl;

  cout << "Por favor, ingrese su edad: ";
  cin >> edad;
  }

  recaudomenor = recaudomenor*menor;
  recaudomayor = recaudomayor*mayor;

  cout << "\n\nFin del día." << endl;

  cout << "Total de clientes: " << cliente << endl;

  cout << "Total de menores de edad: " << menor << endl << "Dinero recaudado: $" << recaudomenor<< endl;

  cout << "Total de mayores de edad: " << mayor << endl << "Dinero recaudado: $" << recaudomayor << endl;

  cliente = cliente-mayor-menor;
  recaudo = recaudo*cliente;

  cout << "Total de adultos: " << cliente << endl << "Dinero recaudado: $" << recaudo << endl;

  int recaudototal = recaudo+recaudomayor+recaudomenor;

  cout << "Recaudo total: $" << recaudototal;
  return 0;
}

what i do here is applying a discount to a child or an elder, taking a count of how many clients we have in a day and the money earned.

it all keeps going until i type -137 cause is my secret code. typing -137 checks the day and counts everything. its awesome.

Btw its all wrote in spanish cause im from México and i dont know if redit has spanic people, i´m also new in here.


r/cpp_questions • • 1d ago

OPEN built a Schnorr ZKP in C++ how can I make it more secure?

2 Upvotes

whenever I search online or ask AI's how to get cryptographically secure random numbers in C++, all I get is overcomplicated setups with huge libraries. what is the cleanest, simplest way in practice to make secure randomness into a small C++ learning project like this? Also open to any general feedback on the protocol structure

Repo: https://github.com/dev-dawud/ZeroKnowledgeProof


r/cpp_questions • • 1d ago

OPEN Would you use AI to port your own C++26 library to C++17?

0 Upvotes

I've been developing an open-source C++ networking library called LightnerX.

I wrote the library myself, designed its architecture, came up with the communication protocol, and made all the major design decisions.

The problem is that I originally built it using C++26, including modules, import std, and other modern C++ features.

Now I've realized that targeting such a recent standard severely limits how many developers can actually use it, so I've decided to port the entire library to C++17.

That means replacing modules with traditional headers and source files, adapting newer language and library features, reorganizing parts of the build system, and making sure everything still behaves exactly as intended.

Doing all of that manually would be a massive amount of repetitive work.

So I'm considering using AI coding agents to handle much of the migration.

To be clear, I'm not asking AI to design the library or invent its architecture.

All of that already exists and was developed by me.

I'd be using AI primarily to translate and adapt an existing codebase to an older C++ standard.

I'd still be responsible for reviewing the changes, writing detailed prompts, running regression tests, checking for behavioral differences, and making the final technical decisions.

I'm curious what other C++ developers think about this approach.

Would you consider this a reasonable use of AI in software development? Or would you still prefer to do the migration manually, even if it takes significantly longer?

I'd especially like to hear from anyone who has used AI for large-scale C++ refactoring or version migrations.


r/cpp_questions • • 1d ago

OPEN How could i do operations on multidimensional Arrays where the Cell might not be there ?

3 Upvotes

One of the assignements for home our professor gave us was :

-a 10x10 Matrix using multidimensional arrays

-the matrix contains all 1s and 0s

-count how many "Islands" there are (a 1 that's Has only 0s next to It in every direction)

My problem Is, i could do a pretty long line for where It checks every generic Cell [ ] [ ] next to One given, but what if that Cell Is in a position where it doesnt have cells next to It In some directions, for example, if the 1 was in a corner ?


r/cpp_questions • • 1d ago

SOLVED x1 and x2 give me "nan"

4 Upvotes

Can someone tell me what is wrong with the operations?

#include <iostream>
#include <cmath>

int main()
{
    double a = 0;
    double b = 0;
    double c = 0;
    

    std::cout << "===CALCULADORA DE ECUACIONES CUADRATICAS===\n";
    std::cout << "ingrese el coeficiente a ";
    std::cin >> a;
    std::cout << "ingrese el coeficiente b ";
    std::cin >> b;
    std::cout << "ingrese el coeficiente c ";
    std::cin >> c;

    std::cout << "tu ecuacion es " << a << "x^2 + " << b << "x + " << c << " = 0\n";
    const double x_de_vertice = -b / (2 * a);
    double solucion1 = x_de_vertice + sqrt(pow(b, 2) - 4 * a * c) / (2 * a);
    double solucion2 = x_de_vertice - sqrt(pow(b, 2) - 4 * a * c) / (2 * a);
    
    std::cout << "===========================================\n";
    std::cout << "el valor del vertice es " << x_de_vertice << "\n";
    std::cout << "x1 vale " << solucion1 << "\n";
    std::cout << "x2 vale " << solucion2 << "\n";

    
}

r/cpp_questions • • 1d ago

SOLVED I want to display de vertix of the quadratic equation

1 Upvotes

we all know that the vertix of a parabola is (-b)/2*a

Well, i know that this thing cant be displayed as an integer so, what should be the correct variable declaration?

my line: vertice = (-b) / 2*a;


r/cpp_questions • • 1d ago

SOLVED Modifying an int variable

0 Upvotes

I forgot how i was supposed to initialize it. Maybe is not the one im suposed to use.

Straight to the matter: How to initialize it if i want it to be any number possible (only integers)


r/cpp_questions • • 1d ago

OPEN How can I use time in my project?

2 Upvotes

I'm currently developing a c++ RPG textgame and I want to know how to improve the combat in my game. Currently it's just a turn based punch trade. How can I make the enemy hit someone for example once every 5 seconds? I know that I'll need specific libraries () which I installed by I don't know how to use them and what to do.

https://onecompiler.com/cpp/44qwdefz6

\\=> This is my project which I need help with.


r/cpp_questions • • 1d ago

OPEN Any sources to learn how C++ source projects get lowered from source code to intermediate representation and eventually to code gen part.

3 Upvotes

Can someone help me out....I'm not able to find any proper sources to follow how c++ projects get lowered from sources codes with headers and archive files to intermediate representation and then object files and shared files and linking like how do they work and their internals ....just trying to learn about them.


r/cpp_questions • • 1d ago

OPEN C++ systems route,will start building redis from scratch as a project,any guidance will be appreciated

30 Upvotes

Hey all, 2nd-year CS student from India.I want to go the C++ systems route.

I just started building Redis from scratch with the "Build Your Own Redis" book. The book is in C, and I'm planning to write mine in C++.

Would love advice on:

1.What should I learn alongside it? (Linux, networking, concurrency, debugging tools, etc.)

2.Any pitfalls when following a C book but writing C++?

3.What project should I build after Redis? I'm thinking a storage engine or something database-ish.

4.Good resources or open-source codebases to read?

5.What do systems roles expect from someone early in their career?

6.Is it even a probably and realistic career option or not?

I am also pursuing competitive programming in cpp

Any guidance would be highly appreciated as to what do u think abt my trajectory and what would be the best possible route to follow according to you

Any "I wish I'd known this earlier" advice is welcome.Thanks in advance looking forward ro some great guidance:)


r/cpp_questions • • 2d ago

OPEN Designing a C++ ML library from scratch — would you prefer A.transpose() or transpose(A) or A.T()?

16 Upvotes

I'm currently building a machine learning library from scratch in C++, and I'm thinking about the API design for tensor operations.

For a transpose operation, I'm considering these interfaces:

Option 1: Tensor B = A.transpose();

Option 2: Tensor B = transpose(A); Option 3: Tensor B = A.T();

I'm curious about what other C++ developers would prefer when using a library.

Which syntax feels more natural and readable?

Thanks!


r/cpp_questions • • 2d ago

OPEN Finalizing performance project

1 Upvotes

So I'm closing up on a project I've been working on for a few months and it involved profiling using performance tools to improve speed ups. My question is, should I include these benchmarks in the final github, or is the whole point really to just show off pure functionality while stating in your resume how you optimized on performance


r/cpp_questions • • 2d ago

OPEN std::greater is not std::greater{} - but why?

15 Upvotes

NB: This is not a technical question, I understand the difference between classes and objects of that class type.

What I mean is, the standard could have been different:

std::ranges::sort(some_range, std::greater); //does not compile
std::ranges::sort(some_range, std2::greater); //compiles

assuming this change:

namespace std2 {
    auto constexpr greater = std::greater{};
}

Letting greater be the name of an object, rather than a type, would have far better ergonomics - but it's a type. Does the current approach have a benefit or is this just a missed design improvement?


r/cpp_questions • • 2d ago

OPEN where should i start?

12 Upvotes

i am completely new to C++ , but i have learned the basics like datatypes, variables , if/else statement, loops, and other things that a beginner should learn , but after learning this, now I'm more confused and i don't know what to write and how to write properly, inshort i think i'm still not able to create that flow in program which a program should have , and now i have 2 months left for an exam , and i'm in such a condition where everything got blank in front of me . I will appreciate it if anyone experienced would help me to get better at c++ and clear that confusion from my head .( and if possible guide me exactly what I should do to create logic and flow in a program??)


r/cpp_questions • • 2d ago

OPEN What's the best way to learn C++ effectively as a 4th semester BTech student?

0 Upvotes

Hey everyone!

I'm currently in my 4th semester of BTech and want to start learning C++ seriously. I'm still a beginner and would love some advice from experienced programmers.

I'd like to know:

  1. What are the best free resources (courses, YouTube channels, websites or books) to learn C++ from scratch?

  2. What's the best roadmap to follow, and in what order should I learn the concepts?

  3. How should I balance learning theory, writing code and solving problems?

  4. When should I start learning DSA?

  5. What would you recommend if you were starting C++ from scratch today?

I'm looking for an effective learning approach rather than just a list of resources.

Thanks in advance!


r/cpp_questions • • 2d ago

OPEN Question

0 Upvotes

¿Is it possible to use FoldCode in a horizontal view?

i can only see it in a vertical view.


r/cpp_questions • • 2d ago

OPEN Strong exception guarantee for copy assignment: is copy-and-swap always the best approach?

6 Upvotes

I've been working on a C++26 networking library, and a recent technical audit uncovered an interesting exception-safety problem.

One of my classes, ConnectionManager, maintains several related data structures:

  • A vector of connection handles.

  • A reverse lookup map.

  • Client ID allocation state.

  • A count of active connections.

The original copy assignment updated these members sequentially.

If an allocation failed while copying the reverse lookup map, the object could end up with inconsistent internal state.

The fix was to prepare a complete copy before replacing the destination's state using non-throwing move operations.

I also added tests injecting allocation failures at different points to verify the strong exception guarantee.

This solved the issue, but it raised a broader question for me:

When designing classes that own multiple related containers, do you generally prefer copy-and-swap, explicit transactional assignment, or disabling copy operations entirely?

I'm particularly interested in trade-offs involving performance, exception guarantees, and maintainability in low-level libraries.


r/cpp_questions • • 3d ago

OPEN Reading material to learn cpp and dsa in cpp

8 Upvotes

Hi all, Indian cs major here. I tried following few video lectures on yt to learn cpp and dsa in cpp. But i keep on getting stuck in a loop of passive watching without any real learning.

I feel reading about relevant topics will suit me better. It will be of great help if I receive some advice on relevant reading material to learn cpp and dsa. Thanks guys.


r/cpp_questions • • 3d ago

OPEN Public and private classes

24 Upvotes

Is there such a thing as private / public classes in C++?


r/cpp_questions • • 3d ago

OPEN Resources for implementing low-level concurrent and asynchronous systems in C++

13 Upvotes

I've been spending some time studying concurrency and asynchronous programming in C++. I have a reasonable understanding of concepts like threads, thread pools, non-blocking I/O, event loops, coroutines, and reactor/proactor patterns.

However, I feel there's a big difference between understanding how these things work and actually being able to implement them.

I'm interested in building things like network servers, runtimes, databases, and other systems software. I'm also working on a compiler, so understanding the internals of these systems is something I'd like to get better at.

What I'm looking for are resources that go beyond explaining the concepts. Books, papers, articles, courses, or open-source codebases that actually helped you implement these kinds of systems yourself.

Some areas I'm particularly interested in:

  • Non-blocking I/O and I/O multiplexing

  • Event loop implementations

  • Reactor and Proactor patterns

  • Coroutines and asynchronous runtimes

  • Thread pools and task scheduling

  • Performance and scalability in concurrent systems

I've already read a few books on concurrency, including some focused on C++, but most of them tend to focus on the programming model and how to use the standard library (threads, mutexes, futures, etc.). That's useful, but it's not quite what I'm looking for anymore. I want to understand how these things are actually built, preferably in C++. For example, implementing a thread pool, an event loop, an asynchronous runtime, or a network server rather than just learning how to use existing ones. I'd really appreciate recommendations that take this implementation-oriented approach.


r/cpp_questions • • 3d ago

OPEN Guide me please... !!

9 Upvotes

I am a C++ developer with 5 years of experience, primarily building ROS nodes, alongside minor embedded work (Arduino/ESP) and application-layer software for an elevator CPU and a chip-manufacturing equipment scheduler (not core embedded).

Despite my experience, I feel directionless and face constant rejections from product-based companies. What specific skills should I focus on next to secure my career —such as application development, socket programming, multithreading or what else ? I feel like I'm nowhere.


r/cpp_questions • • 4d ago

OPEN Is this code clean OOP?

0 Upvotes

Hey so I'm more new to OOP, virtual func's, and inheritance. I was wondering if my code was clean enough for basically a template to look back on later in the future when my tiny brain forgets what virtual func, and inheritance is or well forgets how to code them.

#include <string>
#include <iostream>


struct Vector2 {
    int x, y;
};


class Entity {
    private:
        Vector2 pos;
        Vector2 size;
        std::string entityType;


    public:


    Entity(Vector2 e_pos, Vector2 e_size, const std::string& e_type) : pos(e_pos), size(e_size), entityType(e_type) {}


    Vector2 getPos() const {
        return pos;
    }


    Vector2 getSize() const {
        return size;
    }
    
    virtual void print() const {
        std::cout << "Entity: " << entityType << '\n';
    }


    virtual ~Entity() = default;
};


class Player : public Entity {
    private:
        std::string name;


    public:
        Player(const std::string& p_name, Vector2 startPOS, Vector2 p_size) 
            : Entity(startPOS, p_size, "player"), name(p_name) {}
};


class Orc : public Entity {
    private:
        std::string weapon;
        
    public:
        Orc(const std::string& o_weapon, Vector2 startPOS, Vector2 o_size) 
            : Entity(startPOS, o_size, "orc"), weapon(o_weapon) {}


    void print() const override {
        std::cout << weapon << '\n';
    }
};


int main() {
    Vector2 startPos = { 100, 100 };
    Vector2 size = { 64, 64 };


    std::string hero = "hero";
    std::string orcWep = "HeroSlayer100";


    Player player(hero, { 20, 30 }, size);
    Orc orc(orcWep, startPos, size);



    player.print();
    orc.print();
    
    return 0;
}#include <string>
#include <iostream>


struct Vector2 {
    int x, y;
};


class Entity {
    private:
        Vector2 pos;
        Vector2 size;
        std::string entityType;


    public:


    Entity(Vector2 e_pos, Vector2 e_size, const std::string& e_type) : pos(e_pos), size(e_size), entityType(e_type) {}


    Vector2 getPos() const {
        return pos;
    }


    Vector2 getSize() const {
        return size;
    }
    
    virtual void print() const {
        std::cout << "Entity: " << entityType << '\n';
    }


    virtual ~Entity() = default;
};


class Player : public Entity {
    private:
        std::string name;


    public:
        Player(const std::string& p_name, Vector2 startPOS, Vector2 p_size) 
            : Entity(startPOS, p_size, "player"), name(p_name) {}
};


class Orc : public Entity {
    private:
        std::string weapon;
        
    public:
        Orc(const std::string& o_weapon, Vector2 startPOS, Vector2 o_size) 
            : Entity(startPOS, o_size, "orc"), weapon(o_weapon) {}


    void print() const override {
        std::cout << weapon << '\n';
    }
};


int main() {
    Vector2 startPos = { 100, 100 };
    Vector2 size = { 64, 64 };


    std::string hero = "hero";
    std::string orcWep = "HeroSlayer100";


    Player player(hero, { 20, 30 }, size);
    Orc orc(orcWep, startPos, size);



    player.print();
    orc.print();
    
    return 0;
}

if there are any tips you have let me know!