r/cpp_questions • u/Bliz0w0 • 12h ago
OPEN Learncpp.com
Does anyone know what happened to learncpp.com? There haven't been any new posts there in the last two years. Will the site be updated in the future?
r/cpp_questions • u/AutoModerator • Sep 01 '25
Hello people,
Please read this sticky post before creating a post. It answers some frequently asked questions and provides helpful tips on learning C++ and asking questions in a way that gives you the best responses.
What is the best way to learn C++?
The community recommends you to use this website: https://www.learncpp.com/ and we also have a list of recommended books here.
What is the easiest/fastest way to learn C++?
There are no shortcuts, it will take time and it's not going to be easy. Use https://www.learncpp.com/ and write code, don't just read tutorials.
What IDE should I use?
If you are on Windows, it is very strongly recommended that you install Visual Studio and use that (note: Visual Studio Code is a different program). For other OSes viable options are Clion, KDevelop, QtCreator, and XCode. Setting up Visual Studio Code involves more steps that are not well-suited for beginners, but if you want to use it, follow this post by /u/narase33 . Ultimately you should be using the one you feel the most comfortable with.
What projects should I do?
Whatever comes to your mind. If you have a specific problem at hand, tackle that. Otherwise here are some ideas for inspiration:
ls or wc are good examples.std::vector, to better learn how they work.Post the code in a formatted way, do not post screenshots. For small amounts of code it is preferred to put it directly in the post, if you have more than Reddit can handle or multiple files, use a website like GitHub or pastebin and then provide us with the link.
You can format code in the following ways:
For inline code like std::vector<int>, simply put backticks (`) around it.
For multiline code, it depends on whether you are using Reddit's Markdown editor or the "Fancypants Editor" from Reddit.
If you are using the markdown editor, you need to indent every code line with 4 spaces (or one tab) and have an empty line between code lines and any actual text you want before or after the code. You can trivially do this indentation by having your code in your favourite editor, selecting everything (CTRL+A), pressing tab once, then selecting everything again, and then copy paste it into Reddit.
Do not use triple backticks for marking codeblocks. While this seems to work on the new Reddit website, it does not work on the superior old.reddit.com platform, which many of the people answering questions here are using. If they can't see your code properly, it introduces unnecessary friction.
If you use the fancypants editor, simply select the codeblock formatting block (might be behind the triple dots menu) and paste your code into there, no indentation needed.
import std;
int main()
{
std::println("This code will look correct on every platform.");
return 0;
}
If you want people to be able to help you, you need to provide them with the information necessary to do so. We do not have magic crystal balls nor can we read your mind.
Please make sure to do the following things:
Also take a look at these guidelines on how to ask smart questions.
r/cpp_questions • u/Bliz0w0 • 12h ago
Does anyone know what happened to learncpp.com? There haven't been any new posts there in the last two years. Will the site be updated in the future?
r/cpp_questions • u/Tom_F64 • 16h ago
Here is the "play" function currently:
void play(char **frames, int totFrames){
int i, j;
char music[200];
strcpy(music, DIRECTORY);
strcat(music, FILEMUSIC);
PlaySoundA(music, NULL, SND_FILENAME | SND_ASYNC);
for(i = START; i < totFrames; i++){
resetCursor();
#if DEBUG
char framesCount[100];
sprintf(framesCount, "(frame: %d/%d) \n", i+1, totFrames);
int x=WIDTH-strlen(PROJECTNAME)-strlen(framesCount);
for(j = 0; j <= x; j++)
printf(" ");
printf("%s", framesCount);
printf("%s", frames[i]);
progressBar(i, totFrames, 0, 0);
Sleep(WAIT);
#else
printf("%s\n", frames[i]);
Sleep(WAIT);
#endif
}
}
It starts playing the music and then loads the video frames from a directory which contains every frame of the Bad Apple video one after another. The problem is that the music and the video is initially in sync but slowly drifts out of sync until it's completely out. I think the <chrono> library is what you would use to fix this type of issue but I'm not sure how to implement something that syncs the audio and video while also keeping the video smooth and not slowed down. I've also tried making an FPS limiter but I don't know if this is the right approach. Also I know this looks like C code and it it originally but I converted this program to C++ in order to use libraries like <chrono> and because I generally prefer C++
If you want to see other snippets of code from the program, just ask.
r/cpp_questions • u/YogurtclosetThen6260 • 15h ago
Currently working on profiling a Huffman data compressor and I'm working on optimizing a bit writing bottleneck. For context, the compressor goes through a text file and writes each character's bit representation into a file.
...
ifstream file(inputPath, ios::binary);
char buffer[4096];
while (file.read(buffer, sizeof(buffer)) || file.gcount() > 0) {
streamsize count = file.gcount();
for (streamsize i = 0; i < count; i++) {
char c = buffer[i];
const HuffmanTree::Encoding &encoded = encodings[static_cast<unsigned char>(c)];
writer.writeBits(encoded.encoding, encoded.size);
}
}
...
writeBits takes the encoding and the size of the encoding in bits and writes it into a 4096 size buffer. When the buffer is full, we then use the write function to actually write it into the desired file.
...
void BitWriter::writeBits(uint64_t bytes, uint64_t size) {
assert(size <= 64);
assert(size == 64 || (bytes >> size) == 0);
while (size > 0)
{
const uint64_t available{
8ULL - current_size
};
const uint64_t bitsToTake{
min(size, available)
};
// Select the next highest meaningful bits.
const uint64_t shift{
size - bitsToTake
};
const uint64_t mask{
(uint64_t{1} << bitsToTake) - 1
};
const uint64_t chunk{
(bytes >> shift) & mask
};
current_byte = static_cast<uint8_t>(
(static_cast<uint16_t>(current_byte) << bitsToTake) |
chunk);
current_size = static_cast<uint8_t>(
current_size + bitsToTake);
size -= bitsToTake;
if (current_size == 8)
{
bufferByte(current_byte);
}
}
}
...
Linux perf is indicating this is hot but I'm unsure of what would be a better approach. Any ideas?
r/cpp_questions • u/harshith_7255 • 2h ago
r/cpp_questions • u/AnonymouSfrrrr • 6h ago
I have just set up my vs code for c++ learning on my new device. I was told i can't run modern c++ on older version of this. Is that true? If yes then how do i upgrade?
r/cpp_questions • u/Hour-Scallion-2456 • 1d ago
I mainly use VSCode for my c++ projects, even though I have Visual Studio installed.
My tools are MSYS2, and I have the UCRT64 gcc and UCRT64 ming-make32 as well as cmake.
I set everything up using CMakeLists and git for version control. However, for my compiler, I use g++ and not MSVC even though I have it installed. Is it worth it to swap to MSVC, or will g++ work?
EDIT: Thank you all so, so much for all the insight! I'm probably going to set up clang!
EDIT 2: Again, thank you so much! I have successfully set up clang with MSYS2, and that will be my main compiler now.
r/cpp_questions • u/Grootmaster47 • 1d ago
Hey everyone,
I am currently trying to implement a programming language in C++ after having come pretty far, but ultimately failing to do so in C.
For this, I am taking pretty big inspiration from craftinginterpreters, and am now trying to mimic its implementation of the visitor pattern (entire class at once), written in Java.
However, that implementation uses both templates and interfaces.
As far as I'm aware (the entire internet seems to say so at least), in C++, interfaces are represented by classes whose functions are all virtual.
However, If I try code like the following:
template <typename R> class ExprVisitor {
public:
virtual ~ExprVisitor() = default;
virtual R visitBinaryExpr(const Binary* expr) const = 0;
/* other visitor functions...*/
};
struct Expr {
virtual ~Expr() = default;
template <typename R> virtual R accept(ExprVisitor<R> *visitor) = 0;
};
(Of course, all of my nodes like Binary inherit from Expr. I use structs instead of classes because everything needs to be accessible from the outside for my purposes, so I don't need to re-type "public:" every time.)
Then I get an error on the line declaring the accept method saying
Template function 'R Expr::Expr::accept<R>(ExprVisitor<R> *visitor)' cannot be virtual
on the virtual keyword, as well as one saying
Pure member function 'Expr::Expr::accept<R>' is not virtual
on the = 0 part.
I've googled around a bit, but the only implementations I was able to find were only able to pass in the template type, not get it back out as a return value.
Is it even possible to achieve this? Am I using templates incorrectly? I saw something using variadic templates but was not able to get it working, either.
Any help would be extremely appreciated!
r/cpp_questions • u/Leading_Tax_996 • 1d ago
I was looking on cpprefernce the other day at std::construct_at and I wanted to test the code. But when I ran it it did not compile. I ran the snippet without consteval (and static_assert) and everything worked. Does anyone know what might be the issue? https://en.cppreference.com/cpp/memory/construct_at
Code:
#include <bit>
#include <memory>
class S
{
int x_;
float y_;
double z_;
public:
constexpr S(int x, float y, double z) : x_{x}, y_{y}, z_{z} {}
[[nodiscard("no side-effects!")]]
constexpr bool operator==(const S&) const noexcept = default;
};
consteval bool test()
{
alignas(S) unsigned char storage[sizeof(S)]{};
S uninitialized = std::bit_cast<S>(storage);
std::destroy_at(&uninitialized);
S* ptr = std::construct_at(std::addressof(uninitialized), 42, 2.71f, 3.14);
const bool res{*ptr == S{42, 2.71f, 3.14}};
std::destroy_at(ptr);
return res;
}
static_assert(test());
int main() {
Compiler Error on x86-64 gcc 16.1 -std=c++23
<source>:25:19:
error: non-constant condition for static assertion
25 | static_assert(test());
|
~~~~^~
<source>:25:19: in 'constexpr' expansion of 'test()'
<source>:24:1: error: destroying 'uninitialized' outside its lifetime
24 | }
|
^
<source>:18:7: note: declared here
18 | S uninitialized = std::bit_cast<S>(storage);
|
^~~~~~~~~~~~~
Compiler returned: 1
r/cpp_questions • u/Ex0dusDude123 • 2d ago
I really want to get into programming and want to learn C++, but I really am confused on where to start, and what some things are that can really help me learn and understand everything. So what would be the best ways to learn, such as books or videos and if so which ones? Any advice would be amazing!!
r/cpp_questions • u/shadowslashzzzzz • 1d ago
Hi all, just like the title stated, I know AI is the thing and I have been using it to help me understand on various topic and design on coding. I still learned a lot from AI when I asked a question. But the more I use AI, the more I hate myself on the part where I feel dumb that I cant learn by myself. I've been using CPP to build a small project lately, nothing too fancy but just to refresh my memory from the past. Throughout the process, I tried to limited the use of AI and use documentations and forums like stackoverflow to check out my questions, but in the end of the day I either ended up cant understand the documentation, got overwhelmed by the answers, or just can't find what I needed. Eventually I have to return back to AI and ask the same question and let AI to break it down while also to get feedback on my ideas. I don't hate AI in general (but I hate my dumb self instead), using too much AI is going to kill my thinking skills, I want to try my best to avoid that scenario.
The thing is that I always got overwhelmed by advanced topics no matter in Java, Python, JavaScript, or CPP. Like I can understand the fundamental stuffs very easily, but gets bottlenecked as soon as I deal with advanced topics (anything beyond the basic oop stuffs and general algorithms).
Thank you so much for your time to read this big chunk of paragraph and I apologize in advance if my question sounds dumb.
r/cpp_questions • u/Alternative_Oven696 • 1d ago
Sorry about the title, I should have read the guide first. I am really new to C++. I am going through the practice guide on a youtube video. The test was to make a fahrenheit to celcius conversion. This is what I wrote and it is below.
The teacher added double celsius = (fahrenheit -32) / 1.8;
Then added the std::cout for it. Mine works fine. I am assuming his is better but I am missing it. c++ has made me question my mental capacity.
#include <iostream>
int main() {
std::cout << "Enter degrees in fahrenheit ";
int fahrenheit;
std::cin >> fahrenheit;
std::cout << " Degrees in celcius " << (fahrenheit - 32) / 1.8;
return 0;
system("<pause>0");
r/cpp_questions • u/controversial_slur17 • 1d ago
I'm building a general purpose small container, with a fixed known capacity.
It's basically a thin wrapper around a C array. But, in case I would need to store objects without default constructors, I thought I might make another version of the same container, that would allocate the necessary memory on the heap without building anything inside.
But I'm afraid I opened up a whole new can of worms. The first idea I had was to do the same, but replace my array with an std::vector of appropriate capacity. But I'm sure there are better ways, maybe use "operator new" but I'm not quite familiar with all the methods to properly align memory.
I guess the question is : do C++ people often do that kind of low level memory managing or is the better practice to build around common tools (such as std::vector) ?
r/cpp_questions • u/Jaca_135 • 1d ago
Hi I have a question about VSC. I'm used to compiling and running programs by clicking an button in UI like in arduino IDE or panasonic or siemens PLC enviroments. When i run a C++ program via F5 button everything works just fine (i mean the value near cout appers in the terminal), but when i run it through UI button i uperright corner, selecting any of the options it does not appear
r/cpp_questions • u/Responsible_Invite30 • 1d ago
Is this c++ course still relevant even though it is 8 years old? https://youtu.be/vLnPwxZdW4Y?si=m63NVhTp2kYVkVaC
r/cpp_questions • u/Busy-Consequence-926 • 2d ago
Hey everyone, I found that LearnCpp is one of the best resources for learning C++, and after looking through the website, I really like how the content is organized from the basics all the way to advanced topics.
The reason I’m making this post is that when we learn something on our own, there are so many different ways to approach it. Sometimes we spend a lot of time learning the hard way and later realize there was a much better approach. Other times, we might not make much progress simply because our learning strategy isn’t very effective.
So I’d like to hear from people who have learned C++, especially those who used LearnCpp.
How did you start and progress from beginner to more advanced C++? If you used LearnCpp, how did you go through it? Did you complete it chapter by chapter, or combine it with other resources?
At what point would you recommend starting projects? Are there certain chapters or topics someone should understand before trying to build real projects?
I’d also really appreciate any advice about:
1. What to practice alongside LearnCpp?
2. When to start LeetCode/problem solving?
3. Beginner → intermediate → advanced project ideas?
4. Other resources worth using?
5. Common mistakes or inefficient ways of learning C++?
6. A good roadmap for becoming genuinely confident in C++?
And one final question: At what point would you consider someone proficient enough in C++ to confidently list it under the Skills section of their resume, especially when applying for internships or entry-level positions? What should they realistically be able to do on their own?
Basically, if you were starting C++ again today, knowing what you know now, what path would you follow?
r/cpp_questions • u/evilsyntax • 1d ago
I've been trying to assign a function with a bool as the return to a std::map so I can eventually get around having a big switch statement. I am having issues getting it working though. If anyone has any suggestions that would be appreciated.
Here's a snippet of the code: https://pastebin.com/hTnaDXF3
Trying to assign it directly causes this error: Error (active) E0349 no operator "=" matches these operands
operand types are: std::function<bool ()> = bool () candidate function template "std::function<_Fty>::operator=(std::reference_wrapper<_Fx> _Func) [with _Fty=bool ()]" failed deduction function "std::function<_Fty>::operator=(std::nullptr_t) [with _Fty=bool ()]" does not match because argument #1 does not match parameter candidate function template "std::function<_Fty>::operator=(_Fx &&_Func) [with _Fty=bool ()]" failed deduction function "std::function<_Fty>::operator=(std::function<_Fty> &&_Right) [with _Fty=bool ()]" does not match because argument #1 does not match parameter function "std::function<_Fty>::operator=(const std::function<_Fty> &_Right) [with _Fty=bool ()]" does not match because argument #1 does not match parameter
The second line I was trying to use causes this error: Exception thrown at 0xCCCCCCCC
r/cpp_questions • u/Historical-Wafer817 • 2d ago
I started learning C++ a while ago from various YouTube channels, but they only really helped me with the theory.
I watched Apna College, Bro Code, and CodeWithHarry.
However, I'm still struggling with the syntax, let alone building the logic. I want to learn practically what do you guys recommend?
r/cpp_questions • u/redditsucksnstuff • 2d ago
Hello y'all.
First some quick background. I have been tooting along the tutorials available on the learncpp.com website. I wanted to pick it up and work on some personal projects. So far so good.
To the point. While going through these tutorials, I've had an aching concern in the back of my mind, and I'm hoping I'm in the right place to find the correct expectation of the situation.
The question:
Am I going to end this tutorial with applicable knowledge, or will this be a situation where the tutorials will leave me with some decent fundamentals but little to actually work with?
And a followup question:
If the answer is the latter, what is a good place to get that "in the jungle" knowledge? Are there good resources for that sort of thing? Do I just hang and engage in this sub? What's a good place to get the practical side of things figured out?
I deeply appreciate any insight on this matter. You all have a good day.
Note 1: the current plan is to go through this tutorial then bone up on some tangential materials (Blender, UE, etc.) then go from there.
Note 2: I have a buddy who plans to learn this stuff too to collaborate. It will be a good while before they're caught up though.
r/cpp_questions • u/Alive_Jury4864 • 2d ago
I’ve been learning to write SIMD recently but I’m a bit fuzzy on when I would rely on compiler vs doing it myself
On one hand the compiler doing it saves a lot of code/hassle and it can likely do a good job
But if my application is something performance critical do I want to rely on the whims of the compiler or should that be baked into the application logic itself with manually written SIMD?
I did find that there is a flag you can pass and it will dump out which loops it did/didn’t vectorize which is handy
I guess I’m wondering what’s the typical practice for high performance c++ applications?
Do they write their own or rely on compiler?
r/cpp_questions • u/TheRavagerSw • 2d ago
Recently, I began some work trying to improve my build speeds for debug builds.
I adopted mold, and built a fully static clang executable with mimalloc and llvm libc with very aggressive optimizations.
I managed to achieve %20 speedup over my previous clang which had -O3 but not much else.
I'm planning to use pgo + bolt to gain last bits of performance I can get.
The problem I have, is that I don't know what a good workload for clang would be to use BOLT.
Any recommendations?
r/cpp_questions • u/Minute-Strain5099 • 2d ago
I have 1.5 YOE as a C++ backend engineer, I am confused about my next path, I see the options below, please suggest
Pivot to AI, building RAG applicants, LLM apis, MCP, python
Stay in C++ backend, DSA + System Design
Game development, Vulkan, openGL
CUDA, drivers
switch to embedded C++ , RTOS, suggest path resources for this
EDA domain C++, suggest and resources for this
Target tech agnostic SDE roles focused on DSA system design interviews of
C++ computer networking roles, TCP/IP, communication protocols, socket programming
I am already upskilled in AI SDLC claude, Copilot, Codex
Please suggest which of above paths to focus
r/cpp_questions • u/Intelligent_Hat_5914 • 2d ago
I am making a tui libary where all the different things that can render are called widget like text,box, flex container, progress bar, etc.
I was using inheritance for this and all because all the container widget, multi or single child container had like lot of things common and the widgetTree contains the root widget
Each widget need two function
Layout and render ( or setRectFor child or children because render is same for most parents ) and to solve this, I did need polymorphism for this.
But the problem came later when I need to change layout ( because it wouldnt work for some widget ) and I had to rewrite all the widget,multichildwidget,singleChildWidget which means I have to rewrite all other widget as well
then later I need to change the implementation on how layout is done again, got to do rewrite
then later came scroll container, to make it effiencent I had to change things as well, had to do the rewrite
I got tried of this and now want to use composition instead of inheritance and never want to deal with it again ( I know this happened because of premature optimization where I saw widget with multiple children have lot of same things and most widget having a lot of same things )
Due to that, I am doing a rewrite again :_( but this time, I can make the code more modular.
But I got stuck on widgetTree, how do you get a tree if all the node dont have the same type?
I asked gpt but it said to use node with void* which I dont want to use because we got unique pointer and stuff to avoid new and malloc
The other option is union but that would mean all widget would have the size of the biggest widget which I dont want to use.
Then there is varient, I dont knwo much of this but I looked into it in cherno's video and geeksforgeeks page on this and turns out, it is just union but you know which type it is using. I am currently thinking this
I just can't find a way to do the tree effiency without polymorphism.
r/cpp_questions • u/whimsy-penguin • 2d ago
I am looking for someone to give me a mock interview on c++ internals, system design, and architecture. Specifically modern c++.
Is anyone available to help?
r/cpp_questions • u/Ok_Being6831 • 3d ago
Im working on a project which requires alot of ui stuff and its in the terminal, so i started using ftxui. I went over the docs and they were great but they just skimmed through the basic stuff, they didnt even mention some of the components. Ive just been stuck for 2 days trying to get this working. Going through the src code, examples... nothing really works and idk what to do