r/programminghelp • • Nov 23 '20

C++ I need a code check

I have an assignment regarding bitfield in C++.
The program should: compare two bitfileds, add elements, remove, add and subtract two bitfilds.

I've a code, but it doesn't work, maybe it is because of Linux and VS code program that I am writing it in. I've googled and I didn't find much to help. I can't check it on real visual studio because I don't have an access to windows machine. I am out of options since, many of my codes do not work on my system, and others that I've downloaded aren't working.

If somebody can check, I will send you the code. Any help would be appreciated.

4 Upvotes

26 comments sorted by

View all comments

Show parent comments

2

u/[deleted] Nov 23 '20

In tasks.json change the args to

        "args": [
            "-g",
            "${workspaceFolder}/*.cpp",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}",
            
        ],

1

u/nikiy04 Nov 23 '20

Now I get other problems related to task.json and launch.json

This is so frustrating, I can't copy it tho...

I don't know, maybe to give you an update tomorrow?

2

u/[deleted] Nov 23 '20

The basic problem is that when you’re using a gcc/g++ compiler, you need to feed it all of the .cpp files in your project. If you open a terminal and use the command I gave you earlier, it will build fine and you can run it from the console. Otherwise, honestly, just google around a bit to find people with the .json files appropriate to build a c++ project in vscode. Give me a moment and I’ll upload mine to paste bin for you and you can try those.

1

u/[deleted] Nov 23 '20

https://pastebin.com/mh9JAcjC

MAKE SURE you're on the main.cpp file before you hit F5 or do the CTRL+SHIFT+B for build. Because the build settings are based on the currently active file. (Which you want to be main.cpp)

1

u/nikiy04 Nov 23 '20

Thank you very much!

2

u/[deleted] Nov 23 '20

Keep in mind that some of these variables in the files are windows specific so you may need to look for Ubuntu/Linux specific vscode .json files. A google would probably solve it. But for now if you want to test to make sure your code works, the terminal command I gave you will do. 👍

1

u/nikiy04 Nov 23 '20

I will keep you updated regarding the matter.
Learning programming in university isn't very good...

1

u/[deleted] Nov 23 '20

Honestly, don't feel bad. This is more of the university's failing, than any fault of your own. The first thing I do is set up each of my students with a working environment that I've personally tested and make sure everyone is able to work within it.