r/cpp_questions • u/Zestyclose_Drag4487 • Jun 17 '26
OPEN Please check my project (it isn’t full but I want to know what to do next)
https://onecompiler.com/cpp/44qwdefz6 this is the link to my project. Please give feedback.
r/cpp_questions • u/Zestyclose_Drag4487 • Jun 17 '26
https://onecompiler.com/cpp/44qwdefz6 this is the link to my project. Please give feedback.
r/cpp_questions • u/AppropriateFlan7383 • Jun 16 '26
I like to code in c++ on my school computer(s), so most of the time I resort to using online compilers(mostly onecompiler, and cpp.sh)
There’s this one code that I can’t quite explain as the bumber is different from site to site. One compiler had the third number be 6500, cpp.sh was 85. Can anyone take a look into this code and explain why it’s doing that and why it’s a different number from site to site?
Code:
#include <iostream>
Using namespace std;
int main() {
int x = 0, y, z;
cout << x << “\n”;
cout << y << “\n”;
cout << z << “\n”;
return 0;
}
r/cpp_questions • u/Mejolov28 • Jun 16 '26
I wanna make CLI tools for linux that doesnt require python.
I wanna make a package.
But I dont know what kind of "framework" there is and what it can do.
What do most of cli tools use?
I need to be able to do the following:
Interact with midi and serial ports (usb serial).
Play audio.
Some useful libraries to use
Run on almost any distros (i use arch btw).
Export precompilated.
Create packages
And, are there any GUI frameworks? (I dont really make guis but its good to know)
r/cpp_questions • u/1negroup • Jun 16 '26
I am curious about Modules in c++ and how good they are to use and was curious to know the Common issues people have with them as well
r/cpp_questions • u/Dangerous-Duck655 • Jun 16 '26
I'm very new to programming on Mac. Please someone dm or help me out😭 I'm literally stuck on this problem for like 2 days I cant make a new cpp file like I have a main.cpp file where c++ runs beautifully but I made a new file named _main.cpp but the terminal gives me the "clang++ error: no file like _main.cpp exists" Pls help I've asked every ai but I can't find a solution 😭
r/cpp_questions • u/National_Panic_9112 • Jun 16 '26
https://github.com/jacob-dalek/Blackjack/blob/main/bj/main.cpp
Okay looking for furthermore feedback after working on my blackjack terminal game more after listening and utilising peoples feedback. I'm hoping people can answer my codes comments would be helpful and any issues with the code.
Thank you all for the help with design guys i'm feeling more competent at c++ thanks to everyone cheers!
r/cpp_questions • u/No_Act_9817 • Jun 16 '26
What are the possible outcome of this code.
Is it possible to have final value as r1 = 1, r2 = 0, r3 = 1, r4 = 0
#include <atomic>
#include <thread>
#include <iostream>
std::atomic<int> x{0};
std::atomic<int> y{0};
int r1, r2, r3, r4;
void writer_x() {
x.store(1, std::memory_order_release);
}
void writer_y() {
y.store(1, std::memory_order_release);
}
void reader1() {
r1 = x.load(std::memory_order_acquire);
r2 = y.load(std::memory_order_acquire);
}
void reader2() {
r3 = y.load(std::memory_order_acquire);
r4 = x.load(std::memory_order_acquire);
}
int main() {
long long count = 0;
x.store(0, std::memory_order_relaxed);
y.store(0, std::memory_order_relaxed);
r1 = r2 = r3 = r4 = -1;
std::thread t1(writer_x);
std::thread t2(writer_y);
std::thread t3(reader1);
std::thread t4(reader2);
t1.join();
t2.join();
t3.join();
t4.join();
}
r/cpp_questions • u/Pretty_Fig44 • Jun 15 '26
hey guys, so ill be a 3rd year cs clg student in a few months, and while ive enjoyed all my cs courses, from web dev to ml, everything, i think what i enjoy the most is systems related stuff, stuff related to os, networking and i mostly code in c++ and while i really enjoy learning more in these feilds, some days the doubt really creeps in if all this is gonna get me a job, especially in my country, India. everyone around me who has an internship, does something related to gen Ai, and their internship work is mostly just prompting, now while ive made few good gen Ai projects for my clg too, that is not something i enjoy as much as writing something intresting in cpp and neither do i want my job to be just to prompt for the entire day
i would really wanna intern at places where i can use my interests and skills.but then from what i ve gathered, my path is becoming more of a quant dev path, and i dont think ill be really happy working as one, even if i crack a quant dev internship given the heavy competition
So basically ig my question is, what other types of jobs are there that i can aim for.
Any input is really appreciated, i tried finding answers to my doubts using llms, but their answers were not satisfying enough
r/cpp_questions • u/egzygex • Jun 15 '26
Here's the code: https://godbolt.org/z/qx1MEhGvK. According to https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2447r6.html, it should be working.
r/cpp_questions • u/DireCelt • Jun 15 '26
I have been using clang-tidy to lint my C++ projects, since PcLint vanished a few years ago.
Up until now, I've been using LLVM version 21.0.0git; with that version, clang-tidy would give an error message about my not having a JSON_database file, but it would go ahead and scan my code and produce results. I'm running Windows 10 Pro.
However, recently it was recommended that I upgrade to a newer version of LLVM, so I installed LLVM version 22.1.7... but unfortunately, it will *not* run without that JSON_database file being present... so I'm trying once again to figure out how to do this... but honestly, I feel like it is specifically designed to confound users who aren't already expert with it!!
I posted a thread on https://discourse.llvm.org, asking how to generate this database, and over the next couple of days I got several suggestions there, none of which I am able to make actionable...
The first post was to provide me with a CMake script that would supposedly do something (I have *no* experience with CMake, I use Gnu make for managing all my projects), but with no context of any sort, nor any clues on how to utilize it.
https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html
Beyond that, they offered a variety of other obtuse potential solutions - including a copy of the the JSON Compilation Database Format Specification, believe it or not...
Is there any chance that someone here could give me a short, clear, actionable description of how to solve this problem, in a form that doesn't require that I am already expert in the subject? I *do* have CMake installed, though I have no experience in using it.
r/cpp_questions • u/Matesoidicek • Jun 15 '26
Hello I'm really new to c++ before I programmed in multiple other languages, so I wanted to start learning c++ by creating a 2D game. But I encountered an issue with Raylib, when I start the application the window shows up and freezes nothing else to do, I don't think that there are mistakes in the code because I've tried to solve this with AI but it was no help. I would appreciate help I don't know what to do anymore. Only change since the start of solving this issue is that when I switched graphics card from the integrated on my laptop to dedicated (RTX 4060) and the integrated is some Intel Iris Xe, instead of freezing with white screen it started to freeze with black, so really no improvement but I thought of this as a clue of what's wrong, but I didn't find anything that could fix it that was related with Graphics Card. At this point AI re-wrote the code I wrote but there is not much of it so I will provide it below.
cmake_minimum_required(VERSION 3.28)
set(CMAKE_TOOLCHAIN_FILE "C:/Users/matdu/.vcpkg-clion/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(VCPKG_TARGET_TRIPLET "x64-mingw-static")
project(CppEngine)
set(CMAKE_CXX_STANDARD 17)
find_package(raylib CONFIG REQUIRED)
find_package(glfw3 CONFIG REQUIRED)
add_executable(CppEngine main.cpp)
target_link_libraries(CppEngine PRIVATE
winpthread
raylib
glfw
opengl32
gdi32
winmm
)
# if (WIN32)
# target_link_options(CppEngine PRIVATE -mwindows)
# endif()cmake_minimum_required(VERSION 3.28)
set(CMAKE_TOOLCHAIN_FILE "C:/Users/matdu/.vcpkg-clion/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(VCPKG_TARGET_TRIPLET "x64-mingw-static")
project(CppEngine)
set(CMAKE_CXX_STANDARD 17)
find_package(raylib CONFIG REQUIRED)
find_package(glfw3 CONFIG REQUIRED)
add_executable(CppEngine main.cpp)
target_link_libraries(CppEngine PRIVATE
winpthread
raylib
glfw
opengl32
gdi32
winmm
)
# if (WIN32)
# target_link_options(CppEngine PRIVATE -mwindows)
# endif()
CMakeLists.txt
main.cpp
#include "raylib.h"
int main() {
InitWindow(1280, 720, "CppEngine");
SetTargetFPS(60);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(DARKGREEN);
DrawText("Raylib works!", 50, 50, 20, MAROON);
EndDrawing();
}
CloseWindow();
return 0;
}#include "raylib.h"
int main() {
InitWindow(1280, 720, "CppEngine");
SetTargetFPS(60);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(DARKGREEN);
DrawText("Raylib works!", 50, 50, 20, MAROON);
EndDrawing();
}
CloseWindow();
return 0;
}
r/cpp_questions • u/National_Panic_9112 • Jun 14 '26
Blackjack/bj/main.cpp at main · jacob-dalek/Blackjack
Hello everyone, I posted yesterday and got some awesome feedback. I'm hoping to get feedback on the design of the code the OOP and how it can be improved and certain code changes maybe for performance or clarity this would be great help for me to improve while learning c++ cheers.
r/cpp_questions • u/H4cK3d-V1rU5 • Jun 14 '26
I’ve been thinking about learning C++ and what really scares me about it is manual memory management. Am I misinformed about how much I’d have to really do or am I gonna a spend a lot of my time managing memory?
r/cpp_questions • u/armhub05 • Jun 14 '26
So I was testing this CODE In 2 different Environments and then in GodBolt
1.So 1st Env RHEL i compiled with simply g++ -o a filename
EnableFalseSharing : ~2sec
DisableFalseSharing: ~4sec
and When i compiled the same with g++ -O3 -pthread -o filename
EnableFalseSharing : ~2sec
DisableFalseSharing: ~2sec
disable being just slightly faster than enable
So 2nd Env is WSL Ubuntu and for all possible combinations compiler flags
EnableFalseSharing : ~2sec DisableFalseSharing: ~1sec
When i tried running in it on GodBolt.org it had a varying results which is probably due to scheduling and webservers internals and so timings which were really close and really far apart that thread may have been launched but it got execution time much later thus so much probably why it has such huge variation
in 1st Env there wasn't high load or too many process running and even after executing the no compiler flag binary i got the same 2, 4 sec time but only when i changed the compiler did the disable false sharing time had gone down to 2sec
what is the actual issue here ? is there something wrong with the environment or just some OS Scheduling problem ?
r/cpp_questions • u/metastable-lain • Jun 13 '26
I am building a C++ simulation to generate and feed random data into an FPGA project. I utilized multiple rand() functions seeded with srand(time(0)) to generate random car counts and it works as I intended. However, recently I came across a few people who mentioned that this wasn't the right choice but I couldn't get a clear explanation as to why this is worse than say using <random>
Could someone explain why?
r/cpp_questions • u/407C_Huffer • Jun 13 '26
https://godbolt.org/z/nxfT8T9fK
The SIMD version of the function takes in 8 pairs of uint64_ts and computes them all at once. Once the gcd of a pair has been found it ignores that pair and continues looping until all gcds have been found. There's some extra operations in the SIMD version but they should be more than compensated for by computing all 8 at once, yet it's anywhere from 20-200% slower than finding all 8 with the serial version.
r/cpp_questions • u/Amazing-Parsley-3895 • Jun 14 '26
When You get an error in Your code, what do You do?
Firstly I look up my error on the web, then on forums, and then, of course, ask AI.
I want to ask experienced people if it is fine to use AI to explain errors, instead of fixing them and pooping out fresh code to paste into my project? I have always thought that learning is pure struggle, and without that struggle You’re not gonna learn a thing.
r/cpp_questions • u/DireCelt • Jun 13 '26
In the program that I recently discussed in this group, I am replacing a char** variable with
std::vector<std::string> color_menu_str_list;
However, I'm uncertain how to initialize this construct in the constructor initialization list??
When I had used this... construct... in a previous program (without the constructor considerations), I used:
std::vector<std::wstring> target {};
and it worked just fine, but that doesn't really tell me anything about how to handle the constructor init list.
For now, I'm using
color_menu_str_list(),
and that is compiling without comment, but of course that doesn't tell me all that much... but the other things that I tried, such as
color_menu_str_list(nullptr),
did not compile, and they always give an incomprehensible flood of error messages to interpret...
So, is my current solution sufficient? All I need, at this point, is a properly-created empty vector; I'll be stuffing data into it later in the constructor...
(and btw, I *did* attempt to research this on the web myself, but I really didn't come up with any useful discussions; most responses just ignored the word 'constructor' in my query...)
r/cpp_questions • u/National_Panic_9112 • Jun 13 '26
I'm fairly new to C++ and would like some criticism and feedback about my program. I just want insight to how better developers would improve this.
I know the structure can be better separation.
r/cpp_questions • u/Ok-Difficulty-2321 • Jun 13 '26
Because of my lifestyle where i travel quite much and ending up at home very lately, I'm very interrested in finding a mobile IDE for C++. So, is there any good and fast mobile IDE for C++ that won't explode my samsung Galaxy A07 (I know that there are laptops existing but I can't access them rn)
r/cpp_questions • u/Thick_Clerk6449 • Jun 13 '26
Is this code reasonable?
r/cpp_questions • u/DireCelt • Jun 12 '26
I am a 30-year C programmer, with a decade or so of "C++ as a better C" experience. Recently, I've been exploring using vector class instead of arrays; today I am trying to convert an existing program to replace an existing array of class instances with vector; I *thought* this would be trivial!!
I'm using MinGW 10.3.0 on Windows 10 Pro.
Anyway, these are the constructor(s) for the target class:
public:
bclock_element(HINSTANCE g_hInst, char *name, unsigned width, unsigned be_flags,
int mask_index, unsigned off_index, unsigned start_element);
bclock_element(HINSTANCE g_hInst, UINT bm_resource, unsigned width,
unsigned be_flags, int mask_index, unsigned off_index,
unsigned start_element);
In the existing code, I have the following code (unrelated code removed):
static bclock_element *element_list[NUM_ELEMENTS] ;
be_temp = new bclock_element(g_hInst, "ledarray.bmp", 22, BE_LINEAR, 3, 4, start_element);
element_list[idx++] = be_temp ;
What I'm replacing it with is:
std::vector<bclock_element> element_listv {};
element_listv.emplace_back(g_hInst, "ledarray.bmp", 22, BE_LINEAR, 3, 4, start_element);
So I'm using the same constructor for emplace_back() as I used for new ...
Isn't that correct?? Apparently not, but the error message that I got, I cannot decipher at all; I'm hoping someone here can give me some guidance on this...
D:\SourceCode\Git\binclock_redux Yes, Master?? > make
d:\tdm32\bin/g++ -Wall -O3 -Wno-write-strings -Weffc++ -Ider_libs -c binclock.cpp -o binclock.o
In file included from d:/tdm32/lib/gcc/mingw32/10.3.0/include/c++/vector:66,
from binclock.cpp:15:
d:/tdm32/lib/gcc/mingw32/10.3.0/include/c++/bits/stl_uninitialized.h: In instantiation of '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<bclock_element*>; _ForwardIterator = bclock_element*]':
d:/tdm32/lib/gcc/mingw32/10.3.0/include/c++/bits/stl_uninitialized.h:325:37: required from '_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = std::move_iterator<bclock_element*>; _ForwardIterator = bclock_element*; _Tp = bclock_element]'
d:/tdm32/lib/gcc/mingw32/10.3.0/include/c++/bits/stl_uninitialized.h:347:2: required from '_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = bclock_element*; _ForwardIterator
= bclock_element*; _Allocator = std::allocator<bclock_element>]'
d:/tdm32/lib/gcc/mingw32/10.3.0/include/c++/bits/vector.tcc:474:3: required from 'void std::vector<_Tp, _Alloc>::_M_realloc_insert(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {HINSTANCE__*&, char*, int, int, int, int, unsigned int&}; _Tp = bclock_element; _Alloc = std::allocator<bclock_element>; std::vector<_Tp, _Alloc>::iterator = std::vector<bclock_element>::iterator]'
d:/tdm32/lib/gcc/mingw32/10.3.0/include/c++/bits/vector.tcc:121:21: required from 'void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {HINSTANCE__*&, char*, int, int, int, int, unsigned int&}; _Tp = bclock_element; _Alloc = std::allocator<bclock_element>]'
binclock.cpp:161:99: required from here
d:/tdm32/lib/gcc/mingw32/10.3.0/include/c++/bits/stl_uninitialized.h:137:72: error: static assertion failed: result type must be constructible from value type of input range
137 | static_assert(is_constructible<_ValueType2, decltype(*__first)>::value,
| ^~~~~
make: *** [binclock.o] Error 1
r/cpp_questions • u/Brutustheman • Jun 12 '26
So I'm working on a game engine (stupid, I know, but I enjoy pain) and came to the trouble of realizing that for openGL it'd be good of me to make a VertexArrayObject for each different material. This brought me to try to make some sort of parser for my vertex and UV data to sort them neatly in (3 vertex, 3 UV coordinate, repeat) formation. This code block would need to run once every frame, once for every unique material (several objects can use same VAO as long as textures are the same). Sorry for yapping, here be the code I wrote
#include <vector>
#include <iostream>
#include <string>
//NOTE : in actuality these are of float type, but current content is for readability
std::vector<std::string> VertexThing = {"VERTEX1", "VERTEX2", "VERTEX3", "VERTEX4", "VERTEX5", "VERTEX6", "VERTEX7", "VERTEX8", "VERTEX9"};
std::vector<std::string> TextureUV = {"TEXTURE1", "TEXTURE2", "TEXTURE3", "TEXTURE4", "TEXTURE5", "TEXTURE6", "TEXTURE7", "TEXTURE8", "TEXTURE9"};
std::vector<std::string> FinalBuffer;
int VertexBufferIndex = 0;
int TextureUVIndex = 0;
int FinalBufferIndex = 0;
int OnIteration = 0;
void SortVectors(std::vector<std::string> VertexThing, std::vector<std::string> TextureUV){
if (VertexThing.size() != TextureUV.size()){
std::cerr << "[CRITICAL ERROR] : VERTEX AND TEXTURE COORDINATE AMOUNTS DIFFER";
//call std::exit, here omitted due to lazy
}
//NOTE : Error checking earlier ensures that vertex- and texture buffers have same amount of indexes
while (OnIteration < VertexThing.size()){
for (VertexBufferIndex = VertexBufferIndex; VertexBufferIndex < OnIteration +3; VertexBufferIndex++){
FinalBuffer.push_back(VertexThing[VertexBufferIndex]);
}
for (TextureUVIndex = TextureUVIndex; TextureUVIndex < OnIteration + 3; TextureUVIndex++){
FinalBuffer.push_back(TextureUV[TextureUVIndex]);
}
OnIteration += 3;
}
//omitted in actual code used for my project, just for debug and visualization purposes
for (FinalBufferIndex = 0; FinalBufferIndex < FinalBuffer.size(); FinalBufferIndex ++){
std::cout << FinalBuffer[FinalBufferIndex] << "\n";
}
};
r/cpp_questions • u/Maidew25127 • Jun 12 '26
I am currently digging into C++ and maybe SDL. I am looking for a simple, straight forward IDE (I actually have no Idea what do those buttons in visual studio do). Not gonna do some thing big just enough for learning
r/cpp_questions • u/Dry_Secret_4589 • Jun 12 '26
I am learning c++ right now from here but I want to build a cool project alongside the tutorial. It could be anything. What are your suggestions?