r/learncpp

840 archived posts · Jun 2012 – Feb 2025

Random post

Started to read learncpp.com a few days ago and here is my first code. Please tell me what could be done better. Thanks!

#include <iostream>
#include <string>


class Pump{
    
    public:
        std::string fuel_type;
        float fuel_price; // in liters
        int fuel_volume; // in liters
    
        Pump(std::string temp1, float temp2, int temp3){
            fuel_type = temp1;
            fuel_price = temp2;
            fuel_volume = temp3;
        };
        
        void set_comb(std::string temp){
            fuel_type = temp;
        };
        
   
2914

u/Stvdent•

For example, wouldn't using "delete" on the address of a dynamic array of size 1 be interpreted the same as using "delete" on an address stored in a pointer? Essentially, as I see it, the same operation is happening: memory is freed at that address, and C++ doesn't "know" whether or not that is the start of an array or not, just that it is a place in memory.

2513


u/hikmatic•

im currently taking a c course but its very dry. doesnt have any projects to help teach concepts. instructor just puts up code in powerpoint , explains a concept and moves right to the next topic. i have no idea how these concepts can be used or why would you choose to work with one over the other. for example like passing by reference or by value. does anyone here know of a good course that they learned c/c++ from. something that allowed them to take the training wheels off and write their own code.

228

Where can I actually learn C++ instead of cheating in my class?

Since the beginning of the semester, my friends and more than half of our class has been cheating in our computer science class. At first I was unmotivated to do any actual learning and just continued to tell myself I’ll learn along the way or I’ll catch up later. There has been tooooooo many laters. For every lab, majority of the class just looks up the answers on chegg, c plus plus, stack overflow or some other website since our professor just gets the lab question from our book. I want to actually learn C++ since I plan to be a software engineer. I want to stop cheating and actually learn the language. I know the basics but

2016


Hello everyone,

A group of enthusiastic CS students and I have created a platform where people can learn new programming languages for free. We teach Python, Java, C++, HTML/CSS, MATLAB, and more LIVE on a weekly basis on our discord: https://discord.gg/MdvrJGF. Our lectures are also posted on www.codetheuniverse.org where you can find videos and lecture notes from previous classes.

C++ lecture: https://notes.codetheuniverse.org/cpp/lecture1.pdf

C++ video: [https://www.youtube.com/watch?time_continue=203&v=8fBdshKIKPY&feature=emb_title](https://www.youtube.com/

192

u/bruce3434•

Just wondering where I can find some resources (preferably books) on how concurrency (and parallelism) is handled modern C++. I am interested about

  • Message passing

  • Data sharing

  • Async functions and executors

  • Parallel iterators (and sending messages/modifying Mutexes from inside them)

192

u/Kevadin•

I think the C/C++ memory management, syntax, pointers, etc. isn't that hard to learn but find the building an executable very confusing.

I'm not sure if I should use CMake or Make or gcc and how do I configure on windows vs linux and how do I learn the steps write CMake and Make scripts and so on.

Should start at a lower level and read a book on compilers or operating systems first?

188

u/lrpinnto•

I'm about to start Part 3 (last part) of Bjarne Stroustrup's Programming: Principles and Practice Using C++ 2 so I'll hopefully be finishing the book in the not so distant future.

I've powered through 99% of the available exercises (until now) in the book and was hoping I could be offered some guidance where to go from here.

I was thinking about doing a small project. Perhaps something simple like a GUI that stores input in files or even using a SQL database. I really don't want to overshoot my abilities. I'd rather have something simple but done properly than to struggle with a project a bit over my league. And I want to be able to display this on my GitHub.

Any suggestions/ideas/r

184

u/LynxesExe•

I know how to create a thread and wait for it to finish, but what about data concurrency and making them actually useful?

All I know is that I should research about what a semaphore is and atomic operations. Does anyone have a good tutorial, book or whatever about multithreading in C++ and the various techniques for multithreaded programming?

Thank's in advance!

184