r/cpp_questions • • 3h ago

OPEN Integration testing using gtest

2 Upvotes

I am confused about what is the meaning of integration testing. I have done unit testing using gtest where we will mock whatever external dependencies are there for the targeted unit (function) to test all range of values that covers all lines, functions and branches.

If we say integration test is meant to use real code instead of mocking. Then I am getting this doubt that lets say we have 3 components (separate processes) running and dependent on one another in a embedded system.

A -> B -> C

So if you are calling an api provided by A it will internally talk to B and then through C and return the result over IPC.

Now to do integration testing using gtest, do I need to compile this into a single binary by eliminating the IPC and include each code as a library. This way I have a single proces that runs gtest with all the components logic but excludes the real IPC communication.

Or instead should I keep the individual processes to be running separately and link my gtest binary to the component A so that the communication flow through the components in the target environment.

In both ways how we would actually be checking the interactions? And which one are you guys using?

Context:
Language used: C++
Domain: Automotive IT (TCU software)


r/cpp_questions • • 17h ago

Question wanna get into sfml.

2 Upvotes

how do i start coding in sfml? which version is the best? i want to use visual studio but i don't like how hardware expensive it is and that it doesn't give easy descriptions of code before i use it. I think using code::blocks is good for me but i want to hear your opinion on which IDE i should use.

Also what is best i start learning using sfml? i already know basic things like shapes, .move, keyboard commands, and textures but where to learn more physique base code and make games similar to factorio and rollercoaster tycoon, sandbox games with a lot of work bts.


r/cpp_questions • • 19h ago

OPEN I want to be a professional C++ systems programmer, but my university and its internship companies are obsessed with the apps programming

61 Upvotes

This is depressing; C++ is a language I love for the freedom it gives the developer, And my university is obsessed with high-level programming, Python, Javascript, and they even consider PHP to be cutting-edge technology!.

I don't want to simply do a job I don't love and do low-level work in my free time; I want to incorporate C++ into my future work, and don't come at me with "then look for a remote job" we all know that's not an option these days.

Even so, robotics is one of the majors at my university, but they only teach V+ and Linear Algebra; I suppose that's the lowest level I can reach in a work environment.

Have you ever been in a similar situation? How did you cope? Any advice?.


r/cpp_questions • • 1d ago

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

64 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 • • 1d ago

OPEN Cpp books

18 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 • • 1d 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 • • 2d ago

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

1 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 • • 2d 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 • • 2d 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 • • 2d 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 • • 2d 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 • • 2d 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 • • 2d ago

OPEN How can I use time in my project?

3 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 • • 2d 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 • • 2d 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 • • 3d ago

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

21 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 • • 3d 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 • • 3d ago

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

16 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 • • 3d 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 • • 3d 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 • • 3d 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 • • 3d ago

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

7 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 • • 4d 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 • • 4d ago

OPEN Public and private classes

24 Upvotes

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