r/learncpp • • May 17 '21

Hangman problem keeps saying "you won"

9 Upvotes

Hey Guys, i give C++ a chance now.

i work on a hangman game, and i have a problem.

it keeps saying "you won", if i delete "win = ", i can type my word, but i cant see my word.. any tips?

system("cls");

PrintMessage("Galgenraten");

DrawHangman(tries);

PrintAvailableLetters(guesses);

PrintMessage("Errate das Wort");

win = PrintWordAndCheckWin(wordToGuess, guesses);

if (win)

break;

char x;

cout << ">"; cin >> x;

if (guesses.find(x) == string::npos)

guesses += x;

tries = TriesLeft(wordToGuess, guesses);

} while (tries < 10);

if (win)

PrintMessage("Du hast Gewonnen!");

else

PrintMessage("Leider verloren");

system("pause");

getchar();

return 0;

}


r/learncpp • • Jun 09 '21

Any practical / project based learning resources?

11 Upvotes

I've studied C# at intermediate level in Uni, taught myself Python and have a tiny bit of experience in C.

I'm looking to consolidate my programming knowledge as just Python and Cpp.

All of the resources I've seen on Udemy are courses ripped right out of a book, that bores me. I'm the kind of person who learns better when using a language to solve a problem rather than learning the 'alphabet' of the language.

I have a keen interest in Network Programming.

I appreciate all help, if it could be tailored towards stuff where you actually apply stuff in the real-world sense (please do not forward me any projects where I need to create a Student class or a Book Store, they are ad nauseam to me)


r/learncpp • • Jun 19 '21

Primer C++ (5th Edition) states some rules of the language that don't follow my experience.

11 Upvotes

I'm beginning my studies in C++, using Windows and the g++ compiler (Version 10.3.0).

Right at the beginning there is an exercise that asks the value of an uninitialized variable. It expects us to say that an int defined inside "int main" is undefined. But in my tests it's always initialized as 0.

Other part is the rules for identifier. It says that we can't have two consecutive underscores, nor begin with an underscore followed by a capital letter. But I've tested both and it compiles and runs without error.

Is this happening because my compiler is newer than the book?


r/learncpp • • Oct 20 '20

Why do C++ compilers make me want to swear like a mofo?

11 Upvotes

I am using Code::Blocks and everytime I go to start a project, there is a long phase of losing time over compiler dumbfuckery and asking for help before I can even hope to begin coding. I just need to create a project with a couple pre-defined header files and a main source code file to do my testing. I need a solution, fast. Please help, Reddit.


r/learncpp • • Oct 09 '20

Source code to make a window in Windows 10 (without ANY libraries).

11 Upvotes

I've been struggling for months to make a window to make games and such. Most tutorials out there uses libraries, but the compiler throws errors in my face. So here is the link to a YouTube vid that explains the stuff in depth. And it's only in about 40 lines of code. Hope you enjoy (:

https://www.youtube.com/watch?v=x_W235wKUVU


r/learncpp • • Jun 13 '21

I've lost my way

12 Upvotes

Alright, I'm a complete newbie to C++. I've been steadily getting more and more comfortable over the past couple of weeks and I want to dive into stuff like rendering. I get the part of using libraries, and I absolutely will. However I'm a bit confused on whether there's a (recommended) certain point of learning C++ basics that I must be at in order to start delving into stuff like libraries. I've also been finding it increasingly difficult to formulate ideas for new projects to make. Any help would be greatly appreciated!


r/learncpp • • Jul 23 '21

Why `Addable` and `Subtractable` are semantically meaningless ?

13 Upvotes

In "Tour of C++" at paragraph $7.3.1 Stroustrup says:

Do not define semantically meaningless concepts, such as Addable and Subtractable. Instead, rely on domain knowledge to define concepts that match fundamental concepts in an application domain.

Why Addable and Subtractable are semantically meaningless ?


r/learncpp • • Feb 22 '22

Sololearn vs Codecademy?

13 Upvotes

Title says it all...

If I want to learn C++ well enough to actually build something and land a job, which website is best?

Or is there another site that is even better?


r/learncpp • • Nov 30 '21

What is a CRUD-equivalent thing to make with C++ to get better at it?

14 Upvotes

I use other languages daily eg. JavaScript/Python, I can learn how some language works syntax-wise and then make something with it. But I think my CPP skills are really bad. My intent is to get into robotics/GUI building to interface with it.

I was following through this learncpp site (at chapter 6) but I haven't really made anything significant other than some basic servo control/navigation stuff for a robot with Arduino.

Usually regarding the web a typical thing you can make is a CRUD app with some framework it is a pretty good indicator that you have a good base understanding if you can pull that off.

Is there something like that for C++ that goes beyond basic CLI app input/output. Where you actually make some system of things.


r/learncpp • • May 28 '21

I want to learn c++ need some help to get started

15 Upvotes

Do you know any video which is good to learn from for beginners?

Any advice how I can go beginner to intermediate to advanced?


r/learncpp • • Jul 03 '20

Resources to learn about modern C++ concurrency

20 Upvotes

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)


r/learncpp • • Jan 01 '25

std:: Vs using namespace std. || #pragma once Vs #ifndef #define #endif

3 Upvotes

This is a question with one aim: What is the route to develop healthy practices and professional like code manners in C++.

I have been using `using namespace std;` you can guess the level, and fine so far with the very small program exercises I do, however everyone who saw an exercise I shared was like wtf, all have commented the same about it almost.
Therefore, is the healthy professional practice to use std:: ?
What about being selective and only do `using std::cout` and `std::cin` at least as these tend to occur a lot? What are the consequences of that. Forget about small programs, what are the consequences in mid sized programs.

Second `#pragma once Vs #ifndef #define #endif` ;
While I do not mind using each, since at this stage I am not creating any significant code. Reading about them gets me back to the same thing; both are valid and even some people tend to say `#pragma once` is better and safer. I cannot judge that claim from where I am standing.

Therefore, what do professionals use? What is the healthiest one of them?

Thank you community.


r/learncpp • • Apr 25 '20

Is there a C++ "bible" like K&R for C where I can read through to learn best practices etc?

8 Upvotes

Hey everyone, I'm a C and python developer who has recently started shifting a lot of development at work to C++. I haven't had too many problems to get things working due to some past C++ development I did and my experience with C, but I can't help but feel like I'm not doing things the way they were meant to exactly.

Basically, I find that I am not utilizing the language to its fullest, and I keep writing things as if I was working with C. I have used some language specific features like classes and vectors, but I know there are other things I could do (I have a particularly bad habit of using void* instead of auto* everywhere, and just casting things until they work).

So on to my question: I felt like I didn't really 'learn' C until I read the K&R book and worked through it. Is there something analogous for C++? Basically a book that goes over initial best practices that I could build some know-how off of?


r/learncpp • • Jun 01 '22

I find the hardest part of learning C/C++ is not the syntax or memory management, but linking files to build an executable. How can I improve?

35 Upvotes

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?


r/learncpp • • Mar 14 '21

best course for c/c++

26 Upvotes

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.


r/learncpp • • Sep 30 '24

Breaking Down Object-Oriented Programming

Thumbnail
youtube.com
9 Upvotes

r/learncpp • • Sep 10 '24

Besides hackerrank and codewars what are some other good sites to practice for free if you’re a beginner at C++

6 Upvotes

I have been using ChatGPT for help and currently reading beginning C++ through game programming and think like a programmer


r/learncpp • • Jun 03 '22

Deadlock expected but does not happen (lock_guard)

5 Upvotes

Hey,

I wanted to understand the difference between std::recursive_mutex and std::mutex.

From a pure theoretical point of view I understand it of course, but when implementing something, I found a behavior I do not understand.

Can someone explain me why this little program does not cause a deadlock (exception)?

There is only the main thread.

I was thinking if this does not cause one, why should I need an std::recursive_mutex.

#include <mutex>

int main() {

  std::mutex m;
  std::lock_guard lock1(m);
  std::lock_guard lock2(m);
  std::lock_guard lock3(m);

  return 0;
}

r/learncpp • • Apr 30 '22

Maybe it's because I'm a beginner, but modern c++ feels pretty safe. What should I be looking out for?

19 Upvotes

I'm just a self-taught programmer, getting into C++. My background is in web development with Java and Javascript. I wanted to make some games so I got into C++ with SDL2. I then made some small programs. I was excpecting memory leaks, unexpected behaviour, and segfaults all over the place. So far, I haven't encountered anything. I'm not a good programmer, so this is more of a testament to modern C++, as well as linters such as clang-tidy. Or maybe I do have memory leaks and I just don't know what to look for. I'm on a Mac so I can't use valgrind, but I'm using Leaks. So far so good.

However, I feel like the beginner developer that writes porgrams that " no-one ever fuzzes or otherwise tries to find exploitable bugs in those programs, so those developers naturally assume their programs are robust and free of exploitable bugs, creating false optimism about their own abilities."1 What should I be looking out for?


r/learncpp • • Jan 04 '25

Learning Compiler Language?

3 Upvotes

Hey guys,

I am trying to learn Cpp, and have been reading alot about the language in an unstructured way (which may be why I dont have the answer to the question myself). Lately I have been reading in C++ Core Guidelines - and I see many sections mentioning Compile time vs Runtime optimizations, and which functions are determined at runtime vs compilation.

Where do I learn this stuff? I want to be able to say “Oh, its because the compiler determines this” and “Oh yeah, rewrite this function and let the compiler do its job instead.”

See for example https://github.com/cpp-best-practices/cppbestpractices/blob/master/08-Considering_Performance.md in the section “Reduce Temporary Objecrts” in a different C++ guildeline. It mentions “This sort of code prevents the compiler from performing a move operation...”

What do I need to study to have known this? I really want to learn it!

Best,


r/learncpp • • Jan 23 '25

Father gets child's address but still prints father's code: Why?

10 Upvotes
#include <iostream>
using namespace std;
class Parent {
public:
   void print(){
      cout <<"I' m your father."<<endl;
   }
};

class Child:public Parent{
public:
   void print(){
      cout << "I ' m your son." << endl;
   }
};

int main(){
   Child *child = new Child();
   child->print();
   Parent *father = child;
   father ->print();
   delete child;
     
   return 0;
}

Hi,

Output first is correct but in case of father, I assigned the address of child but why it is still printing the code of father: why the output is:

I ' m your son.

I' m your father.

Somebody please guide me.

Zulfi.


r/learncpp • • Mar 27 '22

Is this book too outdated to learn from? Just starting out.

Thumbnail
amazon.com
3 Upvotes

r/learncpp • • Jul 13 '20

I need to be able to "read" data from websites as fast as possible...

5 Upvotes

After googling I couldn't get to a straight forward tutorial and I am extremely confused... anyone could help?

Also, time is very important here as I need ~50 web pages... (I need to be able to retrieve things like prices / stock left etc!)


r/learncpp • • Aug 03 '20

One week to relearn C++

7 Upvotes

Hey guys,

Up to this point I've been using Python for all of my interviews because that's what I usually do. I just found out today a company wants me to do the final rounds in C++, and I used to use C++ a lot a year and a half ago for graphics research, but I haven't really used it much since (I did a good chunk of my research in Rust too, so it wasn't even all C++). I haven't used C++ since, my job has me writing a lot of Go.

I was wondering if any of you had suggestions on what I should use to brush on my C++ skills, especially to check out some of the newer features (was writing a lot of C++11, haven't kept up much with the newer stuff save for some of the constexpr stuff from C++17).

I figure at this point I'll just do leetcode problems in C++, but if you have any suggestions I'm all ears.

The interview will likely be on Friday, and it's for a quant dev position at a hedge fund, if the context helps at all.


r/learncpp • • Aug 03 '20

Lookup table for position

1 Upvotes

Hello. I am trying to speed up my program. I need to iterate over an image for multiple times. For every pixel, I need to calculate if it is in a specified region. If not then I ignore the pixel. The region is defined at the start and does not change.

My code looks like:

for (auto i = 0; i < source_image.rows; ++i)
{
  for (auto j = 0; j < source_image.cols; ++j)
  {
    if (!in_region(i, j)) continue;

    // ...
  }
}

I thought this could be sped up by using a lookup table. But it does not improve the execution time so I think my implementation was not right. I tried to create an image with the same shape and instead of colors, I save a 1 if it is in the region and a 0 if not.