Necessary extensions for VS code with Windows OS - c++

I am a first time C++ user, and I have been working for 8 hours trying to build and compile the simple "Hello World" program with C++ in Visual Studio Code. I have CygWin64, but I'm not sure if it's connected to my VSCode. I have installed the extensions C/C++, C/C++ Compile Run, C++ Intellisense, Clang-Format, and Easy C++ projects.
So far I have tried
#include <iostream.h>
main()
{
cout<< "Hi there";
return 0;
}
and
#include <iostream.h>
int main() {
std::cout << "Hello Easy C++ project!" << std::endl;
}
Using iostream.h helped me to get to work (it wouldn't at first), but I'm not sure if that is helpful, since other posts say that .h is very archaic. I have also tried editing my c_cpp_properties.json file. Sadly, I still get the message:
"> Executing task: bash -c "make run" <
'bash' is not recognized as an internal or external command,
operable program or batch file.
The terminal process terminated with exit code: 1
Terminal will be reused by tasks, press any key to close it."
I am not sure if I need to install an alternative to Clang (I haven't found one), or run something initially on Cygwin64.
I have been looking online for suggestions and following pages such as https://dev.to/acharluk/developing-c-with-visual-studio-code-4pb9 and https://github.com/Microsoft/WSL/issues/1598, but I still can't seem to get around this problem.
Any help would be very appreciated.
Thanks,
Anne

Related

Notepad++ NppExec console warning, need explanation "C++"

I've tried using Notepad++ to code c++ and followed a few tutorials on youtube, here's what I did:
-Installed gcc/g++ compiler using mingw64
-Installed NppExec plugin on N++
-Typed in the following compilier script and saved as C++:
NPP_SAVE cd $(CURRENT_DIRECTORY) g++ $(FILE_NAME) cmd /c $(CURRENT_DIRECTORY)\program.exe
Anyways whenever compiling a program, for example a simple program
#include <iostream>
using namespace std;
int main(){
cout << "Online\n";
system("pause"); //So that cmd doesn't disappear immeadiately on running.
return 0;
}
The console displays the following warning:
"C:\Users\pc\Desktop\Courses\Projects\C\program.exe' is not recognized as an internal or external command, operable program or batch file."
My question is, When I run the program on cmd, it runs perfectly but the error displayed during linking says that the folder does not exist in %PATH%
Any explanation?
Thank you!
Ok so, what I basically did was change the script,
cmd /c $(CURRENT_DIRECTORY)\program.exe
To be later
cmd /c $(CURRENT_DIRECTORY)\a.exe
the console worked fine and even received input
Here is a link to a similar problem:
How to compile/execute C++ code from within Notepad++

C++ run error when using endl

I've recently started to learn C++ and I'm trying to compile and run a very simple program.
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
cout << "Hello Again!";
return 0;
}
The program itself compiles as it should without any errors, however, when the program runs, it seems to stop after cout << "Hello World!" << endl;. I find this very strange, as my friend is sitting right beside me, doing the exact same thing and it works for him. The same thing happens when I try to use the sizeof();; it does not return any value, however, when my friend does this, it works.
When I ran it in NetBeans, it first generated the error
RUN FAILED (exit value 255, total time: 2s)
And another time I ran it, it generated the same error, but with a different exit value. Although it is now back to 255.
When running debugger in NetBeans it produces
SIGILL (Illegal instruction)
a few times before it stops working.
I have installed the MinGW compiler at the default directory (C:\MinGW), and this is the compiler that NetBeans and any other program is using. I have also added the path to the System Environment Variables at the end of the "Path" variable:
;C:\MinGW\bin;C:\MinGW\msys\1.0\bin
Trying to run and compile the same code in Atom results in
Hello World!Press any key to continue . . .
I have tried reinstalling the compiler, and restarted my computer. None of which seems to work. I've also tried \n, which works.
My question is, is there anything wrong with my compiler or computer, or am I missing something obvious? And is it possible to fix this?
(Sorry if this is a duplicate, I've searched for a few hours, not able to find anything useful)
I found the culprit!
In my System Environment Variables, C:\MingGW\bin and C:\MingGW\MSYS\1.0\bin was at the bottom of the list. This meant that it was below C:\Program Files (x86)\GNU\GnuPG\pub (Which I think, if I'm not mistaken is another compiler).
Although all paths in NetBeans were correct, it seems like the system didn't like it when another compiler was listed above MinGW.
I solved the problem by moving the paths for MinGW up, above the GNU.

IDE showing blank console

It's been days since I try to make my IDE (Code::Blocks version 13.12, I tried on 10.05 too) work. Any program (including a simple Hello World! program) I would make would show a black console showing nothing but an " _ ". I have made an exception in my antivirus (Avast!) for the file containing the IDE) but the same thing happens . I have tried re-installing twice, i have tried resetting the compiler and debugger's settings to default, auto-detecting toolchain executables ,but the same thing happens.
I have tried rebooting my computer several times, same thing happens.
I would like to know what I can do to solve this problem , because I don't want to get another complicated compiler (I am a beginner,) , as Code::Blocks fits my needs perfectly.
The following codes produces a blank console:
#include <iostream>
int main()
{
std::cout << "Hello world!\n";
return 0;
}
I had the same exact problem, with Eclipse, Visual Studio and then with Code::Blocks (I tested them all). I suggest you follow this video tutorial after you confirm the problem persists with a second IDE : https://www.youtube.com/watch?v=zOGU8fC3bvU&index=6&list=LLHcXdIeBMN4XYRZAk4IeXmg&spfreload=10 . It will take you step by step on how to install a given compiler.

Can't execute compiled C++ exe file

I am having trouble executing my C++ code. I have written a basic "Hello World" program, and compiled it using the g++ make command. Here is my code:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World" << endl;
return 0;
}
I am on Windows 10, using Emacs for code editing, and CygWin for compilation. I saved this file as hello.cpp. I then navigated to the directory in CygWin. Then I did the command make hello. This created hello.exe. Then, I attempted to execute the file using ./hello.exe. I also tried ./hello which also didn't work. When I type one of these commands and hit Enter, it just on the next line, not doing anything. I can type in this blank line, but it won't do anything. Does anyone know a way to make my code execute properly. Thank you.
EDIT: I tried running this at cpp.sh, an online C++ compiler, and it worked fine.
Your program probably is working but the console window is closing before you can see anything.
Try adding an input at the end of the program so it will wait.
I.E.
int a;
cin >> a;
Your code is most likely executing, but not outputting anything. That's because it's failing. Try checking the return value after it has run with echo $?. If it's not 0 then it has crashed. Also run it in gdb and see if it fails. The reason why it's failing is most likely a windows/cygwin clash - it's not your code.

C++ compiling and running in Sublime Text 2

I really like Sublime Text 2 for HTML/CSS and Python and I'm starting to learn C++ and I want to use Sublime Text 2. I have looked at a few tutorials on installing g++ in order to run C++ in Sublime Text 2.
This is my code:
// my first program in C++
#include <iostream>
int main()
{
std::cout << "Hello World!";
}
And when I run it it says [Finished in 1.5s] but nothing got printed. I have added the environment variables path but nothing gets printed.
The problem is that you are pressing build, which compiles your source code into an executable but does not run it. The [Finished in ...s] you are seeing is how long the program took to compile.
What you need to do is build like you currently are, but then go to the directory where your source code is and run the executable file that's in there*. There is a run option within the editor, but it doesn't always work on Windows**.
*if the program closes instantly, try running it from the console or adding std::cin.get() to the end of your program
**often due to incorrect configuration