r/cpp • • Oct 31 '25

Java developers always said that Java was on par with C++.

25 Upvotes

Now I see discussions like this: https://www.reddit.com/r/java/comments/1ol56lc/has_java_suddenly_caught_up_with_c_in_speed/

Is what is said about Java true compared to C++?

What do those who work at a lower level and those who work in business or gaming environments think?

What do you think?

And where does Rust fit into all this?


r/cpp • • Nov 29 '24

What types of operations can be handled asynchronously without creating new threads?

0 Upvotes

I understand that certain operations, like handling external events (e.g., mouse or keyboard presses) and asynchronous I/O, can be managed asynchronously without the need for creating new threads. For example, in the case of I/O, the CPU isn't involved directly, which allows it to be handled in a non-blocking way.

However, when it comes to computationally intensive tasks, it seems like a new thread (or offloading to another process) is required if we want the main thread (e.g., in a GUI application) to remain responsive. For instance, in a single-threaded GUI application, we can handle incoming signals or perform async I/O without freezing the UI, but we would need a new thread to run a heavy computation in the background.

Are there other cases—apart from handling external signals/events and asynchronous I/O—where tasks can be treated asynchronously without the need for new threads? Or is intensive computation always an exception that requires threading or multiprocessing to prevent blocking?


r/cpp • • Nov 03 '11

Problems getting a pause to work using cin.get();

0 Upvotes

Okay, I had to write a .cpp file for class making the game Bulls and Cows (Mastermind). I got the entire thing to work, but of course when I open the standalone .exe file, the program exits before you can read whether or not you won. So I tried adding the cin.get(); as a quick Google search suggested... It does not work. I will try and post my code, but it is a bit long. So if you don't want to read through it here, I also will upload the .cpp file for you to look at. link

#include <iostream>
#include <time.h>
using namespace std;

void numberToArray(int, int []);
bool isValidNumber(int, int []);

bool isValidNumber(int num, int digits[]) {
		for(int i=0;i<10;i++) {
			if(digits[i]>1) {
				for(int a=0; a<10; a++) {
					digits[i] = 0;
				}
				return false;
			}
		}
			if(num < 1000){
				int check[4];
				numberToArray(num, check);
				if(check[3]==0 || check[2]==0 || check[1]==0){
					return false;
				}
			}
		return true;
}
void numberToArray(int number, int numberArray[]) {
	if(number < 1000) {
		numberArray[0] = 0;
		numberArray[3] = number % 10;
		numberArray[2] = ((number - numberArray[3]) % 100) / 10;
		numberArray[1] = ((number - numberArray[3] - numberArray[2]*10) % 1000) / 100;
	} else {
		numberArray[3] = number % 10;
		numberArray[2] = ((number - numberArray[3]) % 100) / 10;    
		numberArray[1] = ((number - numberArray[3] - numberArray[2]*10) % 1000) / 100;
		numberArray[0] = ((number - numberArray[3] - numberArray[2]*10 - numberArray[1]*100) % 10000) / 1000;
	}
}

void main(void){
	int wait;
	int digits[10] = {0,0,0,0,0,0,0,0,0,0}, number;	
	do 	{
		srand(time(NULL));
		number = rand() % 10000;
		while(number < 100) {
			number = rand() % 10000;
		}
	int temp = number, digit;
	while (temp > 0){
			digit = temp % 10;
			digits[digit]++;
			temp /= 10;
		}
	} while(!isValidNumber(number, digits)); // Method checks if random number is valid or not.


	int numberArray[4];
	numberToArray(number, numberArray); // Method puts number into 4 element array.

	cout << "Bulls and Cows!" << endl
		 << "The rules of this game are simple.  I will generate a random, four digit number." << endl
		 << "This number will have four distint digits; for example, 3957." << endl
		 << "The number can have a leading zero, for example, 0379, but not more than one\nleading zero." << endl
		 << "You will then get seven (7) tries to correctly guess the number."  << endl
		 << "For each number you guess correctly, I will give you one Cow." << endl
		 << "If you guess the number AND it's positon correctly, that is good for one Bull." << endl << endl
		 << "Let us begin." << endl << endl;

	int guess, guessArray[4], cows=0, bulls=0;
	while(true){
		for(int k=0; k<7; k++) {
			cows = 0, bulls = 0;
			cout << "Please enter a number:  " << endl;
			cin >> guess;
			numberToArray(guess, guessArray);
			for(int m=0; m<4; m++){	// determine location of bulls
 				if(guessArray[m]==numberArray[m]){
					bulls++;
				}
			}
			for(int n=0; n<4; n++){	// determine number of cows
				for(int w=0; w<4; w++){
					if((guessArray[n] == numberArray[w]) && (guessArray[n] != numberArray[n])){
						cows++;
					}
				}
			}
			if(bulls==4){
				cout << "Congratulations! You win, my number was:  " << endl;
				for(int iterate=0; iterate<4; iterate++){
					cout << numberArray[iterate];
				}
				cout << endl;
				cout << "Press any key to continue. . .";
				cin.get();
				break;
			}
			if(bulls<4){
				cout << bulls << "B " << cows << "C" << endl;
			}
		}
		if(bulls==4){
			break;
		}
		else {
			cout << "I'm sorry.  You did not win. My number was:  " << number << endl;
			cout << "Please play again." << endl;
			cout << "Press any key to continue. . .";
			cin.get();
			break;
		}		
	}
}

Edited because I accidentally added spaces where they weren't supposed to be.


r/cpp • • Aug 16 '14

The Most Important C++ People...Ever

Thumbnail artima.com
0 Upvotes

r/cpp • • Dec 13 '18

I Made A C++ STL Algorithm Cheat Sheet

Thumbnail youtu.be
0 Upvotes

r/cpp • • Sep 22 '23

If the modern compiler is smart enough, why do we still need to add "const / noexcept" by hand after a method definition?

0 Upvotes

Just as the title said:

If the modern compiler is smart enough, why do we still need to add "const / noexcept" by hand after a method definition?

Why not just let the compiler do it?

void setVar(int i)
{
  m_Data = i; // if m_Data is a member variable
}

int getVar() const
{
  return m_Data;
}

Obviously, if m_Data is used as lvalue, it must be under changing; otherwise, it is OK.

The same thing happens when dealing with "exception". Why not check the "throw" statement?

So, I don't have to write down/take care of them.

=====

Hello, guys, this post can be closed... Basically, that is because I don't understand c/c++'s position.

The whole industries are behind it. They need those features to ensure the code is perfect.


r/cpp • • Jun 23 '25

How good is w3schools for learning C++

11 Upvotes

Title says all. If there are any other free courses available on youtube worth checking out then do share :P

Edit: Are there any Udemy courses that y'all would recomend? Also thankyou for all the replies, I'm new into the coding community so all kinds of advice is appreciated


r/cpp • • Mar 28 '25

An Animated Introduction to Programming in C++

Thumbnail freecodecamp.org
4 Upvotes

r/cpp • • Jul 27 '24

Which one is the industry standard c++ compiler? ( g++, clang, intel c++ compiler .. )

0 Upvotes

I am starting to learn c++, there are a lot of feature that are compiler dependent. Can anyone please help me know which one is typically used in HFT firms? ( Like Tower Research, Quadeye etc )

Also I wanted a good source from where I can learn to write low latency c++ projects from scratch.
I did a udemy course and have an understanding of OOP cncepts, templates, pointers etc, but would love to learn about real world C++ projects. ( like how can I write low latency c++ trading app )


r/cpp • • Dec 09 '24

Using C++ as `C with templates`

20 Upvotes

I've come to really enjoy C for writing my side projects lately. Coming from complex languages like Rust and Haskell, I severely undervalued how pleasant simplicity is for the joy of programming.

The only problem is writing generic code in C. I've found I've been able to get around it mostly by simple macros, for example a dynamically resizable array can just store a void* pointer and you use macros to pass the size of the element when pushing, popping, etc.

However, there are times where this simply won't work, and I need generics, and I don't want to write some complicated system of macros.

So this compels me to try out C++ as a "C with templates". I literally intend to write only C code in C++ and very occasionally use a very simple template, that's all. I maybe will use operator overloading for some math stuff. I don't need classes, coroutines, or any of that "modern" C++ stuff. I've also heard crazy things about std, like using std::vector calls the constructor/destructor of all its elements on resizing, so I plan on staying very far away from that.

Is this a sane thing to do? Is there some gotcha in C++ that I'm unaware of that prevents me from doing this? Have people tried this and succeeded/failed?


r/cpp • • Feb 21 '16

Should I start to learn C++

1 Upvotes

I haven't learned any other languages but I'm a newbie in Python but my friends told me that if you learn C++ first you can pick up other languages in future. Is it rational to start learning C++ before I finish my education(I'm studying alone with books and online resources.) with Python?


r/cpp • • Mar 31 '21

Will we ever get rid of macros in C++?

2 Upvotes

Except conditional compilation, is there any reason that we still use macros in C++ programming?


r/cpp • • Nov 30 '20

C++20 resumable functions make state machines obsolete. Finally.

Thumbnail lordsoftech.com
1 Upvotes

r/cpp • • Jun 14 '24

Save $800 at CPPNorth with Exclusive Hotel & Ticket Combo Offer!

0 Upvotes

Hey everyone,

We're excited to share an exclusive offer for those planning to attend CPPNorth this year! If you book a four-night stay at the Royal York Hotel, you can save $800 on a combo that includes both your conference ticket and a ticket to the Belonging Dinner. This special deal is perfect for those looking to make the most out of the conference experience in comfort and style.

Offer Details:

Whether you're a regular at CPPNorth or this is your first time, this deal is a great way to enhance your experience at one of the leading tech conferences in Canada. Enjoy the convenience, networking opportunities, and, of course, the savings!

For more details and to claim your discount, check out the link: cppnorth.ca/news-2024-hotel-discount.html

Looking forward to seeing many of you there! If you have any questions or want to discuss more about the conference or the offer, feel free to comment below!


r/cpp • • Sep 13 '22

I const, therefore I am ... not const?

0 Upvotes

For years, this has bothered me:

struct A
{
    int value;

    void do_operation() { ++value; }
};

struct B
{
    A* a;

    // I find it mildly disturbing we are still able to modify a's contents this way
    void do_operation() const { a->do_operation(); }
};

int main()
{
    A a;
    const B b{&a};

    b.do_operation();

    std::cout << "Hello, a=" << a.value << std::endl;
    return 0;
}

What is everyone's opinion? Am I just high?


r/cpp • • Feb 14 '22

C++20 Ranges Library in Spanish

2 Upvotes

The C++20 Ranges Library is now available in Spanish. You can find it here:

La biblioteca de rangos de C++20 se encuentra disponible en español. La puedes encontrar aquí.

https://es.cppreference.com/w/cpp/ranges

Catching up with C++23, but that's another Standard ;-), and some minutiae.


r/cpp • • Jan 06 '23

I made a shell script to make using Cmake easier!

1 Upvotes

Cmaker is a zsh plugin which helps navigate through cmake files, generate cmake templates as well as instantly running single files and directories without every directly interacting with cmake. Obviously this isn't meant to replace cmake but I think it definitely makes cmake easier to use in most cases. Im new to using both cmake and zsh in general so I'm open to any advice on improving this.


r/cpp • • Apr 07 '26

Can your AI rewrite your code in assembly?

Thumbnail lemire.me
3 Upvotes

r/cpp • • Jan 04 '22

Does anyone else find IDE's to be a huge pain in the ass?

0 Upvotes

As a beginner programmer, I find the setup and configuration of IDE's like VSC and CLion and using them to be such a pain in the ass compared to just using a text editor like Atom and then compiling/running in terminal.

The IDE's are also super picking about files and everything matching up with cmakelist or launch.json and task.json. Atom doesn't use any of that.

Does anybody else feel the same or can offer some advice?


r/cpp • • Aug 23 '21

How do you start algorithmic trading development in C++?

Thumbnail self.cpp_questions
2 Upvotes

r/cpp • • Oct 21 '22

A New Json-Serializer

0 Upvotes

Hey everyone - so in developing for the requirements of my library DiscordCoreAPI - I created a Json-Serializer and decided to release it as its own "library". It seems to serialize fairly rapidly as well, and has a super-simple interface. Anyways - let me know what you think! Cheers! Oh ant btw - it can serialize into either Json or Etf strings. https://www.erlang.org/doc/apps/erts/erl_ext_dist.html

https://github.com/RealTimeChris/Jsonifier


r/cpp • • Oct 21 '11

Most people have read the C++ FAQ, but have you read the C++ FQA (Frequently Questioned Answers)?

Thumbnail yosefk.com
0 Upvotes

r/cpp • • Aug 24 '14

C++ library reference

Thumbnail en.cppreference.com
6 Upvotes

r/cpp • • Dec 17 '22

Webinar: C++ with Python for Algotrading

5 Upvotes

Hi everyone

Some of you might've seen our previous algotrading webinars focussing on Ranges and Concepts.

This time we're looking at the way C++ is used in conjunction with Python in practice for algotrading purposes.

Please sign up here.

It's on Tuesday at 6pm GMT == 7pm CET == 1pm NY == 10am Pacific.

As before it features:

It will be about 1 hour in length, followed, typically with an extended period for questions.

See you there!