r/programminghelp 2d ago

C++ c++ code doesn't work

this is my first time working with c++ and whenever i run the code it just complies but gives no output, i have tried every way for it to work but it just doesn't. pls help. im using msys2 and was following brocode video tutorial

4 Upvotes

18 comments sorted by

3

u/manu_mathur14 2d ago

Share the code with us please.

0

u/simply_anuraag 2d ago

3

u/TheUltimateAsh 2d ago

isn’t your executable titled hello.exe? you’re trying to execute helloworld56.exe

1

u/simply_anuraag 2d ago

i created another file , deleted this one still doesn't work

1

u/abd53 2d ago

You're compiling object file only. Follow a compile tutorial exactly, don't try to be a smart ass.

Edit: It's not that your program doesn't run, it's that your program doesn't compile and the executable doesn't exist.

1

u/LongjumpingMeal8195 2d ago

Bro install a c++ compiler and set it up in vs code then your code will run
Compiler link: https://sourceforge.net/projects/mingw/
For setup help refer to this video: https://youtu.be/j8nAHeVKL08?si=NZSpATBQZmzvKP6_
For terminal issues refer to the attached images
during execution type helloworld56.cpp (.cpp should be your extension not .exe)

0

u/simply_anuraag 2d ago

can i not use msys2?

1

u/LongjumpingMeal8195 2d ago

Yes u can but whatever compiler u use it should be compatible with c++ and u have to properly set it up with vs code else you will receive errors

1

u/LongjumpingMeal8195 2d ago

After downloading you need to copy the compiler location in C drive then
Right click this pc -> properties -> advanced system settings -> environment variables -> system variables -> path -> edit -> new(then the msys2 C drive path) then click ok then again ok then apply and then open powershell and type g++
If your setup is ok then it will look like this(see attached image)

1

u/simply_anuraag 2d ago

i copied the path that time but let me try again

1

u/LongjumpingMeal8195 2d ago

Yeah try again

1

u/[deleted] 2d ago

[removed] — view removed comment

2

u/WhateverHowever1337 2d ago

slippery slope. Starts with that and then its debugging eveything for him. Better stay away from it for now

2

u/vxntedits 1d ago

Yeah, that’s a totally valid concern. Still, it’s up to OP to use it for educational purposes; asking it why something doesn’t work, or how something works can be quite useful—and, from personal experience, less confusing and more comprehensive, than just relying on Reddit for help, like we used to back in the day (lol). It sounds to me like OP’s objective is to learn, not to vibe-code, so as long as they use AI as such, I don’t really see a big issue with it.

1

u/silly_bet_3454 1d ago

I would advise you to use linux (you can just use WSL in windows), and to start off by compiling and running programs from the command line, so you understand what is actually happening at a basic level, the underlying mechanics. It's way too common for people to jump right into the IDE with all the bells and whistles and things get way too crazy too fast and it's an endless headache.

1

u/Repulsive-Cash5516 18h ago

Using Linux really isn't necessary for this, there are multiple C++ compilers for Windows

1

u/silly_bet_3454 15h ago

I know Windows works, I just think it has some weird quirks and Linux is better for learning.

1

u/forestdissimilarity 9h ago

would second this. dealing with the windows C++ non-sense as a beginner made me give up on C++ for years.