Notepad++ NppExec console warning, need explanation "C++" - 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++

Related

gdb <error reading variable> for any string object

Lets take this very simple program here for example:
// test.cpp
#include <string>
#include <iostream>
using namespace std;
int main() {
string str = "Hello";
cout << str << endl;
return 0;
}
now I compile this code with g++ compiler:
g++ -g test.cpp -o test.exe
now I am trying to debug this with gdb:
gdb test.exe
after I set breakpoint on main and then reach the line return 0, I try to see what is in the string str. But I cannot print it in the console. It says <error reading variable>. Not only in gdb console, even Visual Studio Code UI using gdb gives the same output.
Here is a screenshot of my console:
I have searched for this everywhere and the only relevant question I found was this, which did not work.
I also found this post on github VS Code repo issues. The fix suggested there might work I am not sure, I cannot find the setting that he suggested on my Windows 11 machine.
How do I read the value in the string in debug mode?
Edit
After #ssbssa suggested me to update my gcc, I used MSYS2 to get the latest gcc, g++, and gdb versions. Now I have gdb 12.1. Now it is not showing the old error anymore but now it says "Converting character sets: Invalid argument". Still struggling to get it to work.
First run your program with gdb like so:
gdb test.exe
Now inside the command line interface run the command:
set charset UTF-8
This should temporarily fix your problem. The only inconvenience might be that you need to run this line every time you debug on your command prompt with GDB.
I noticed that you are also using Visual Studio Code. You can install C++ extensions for VS Code and there you can add the command set charset UTF-8 in the launch.json setupCommands array as shown here. This way you can debug your application faster.

Necessary extensions for VS code with Windows OS

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

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

C++ compiles but gives error when executed

I am new to Linux Ubuntu 11.10 and have basic C++exposure.
I installed the g++ by
sudo apt-get install build-essential
and created a directory cpp in my home directory. I then wrote a program hello.cpp in my cpp directory
#include <iostream>
using namespace std;
int main() {
cout << "Hello !" ; return 0;
}
and compiled using
g++ -W hello.cpp -o hello
The program compiles without any errors/warnings. When I try to execute the file
./hello.cpp
I get error messages:
line 3: using: command not found
line 6: syntax error near unexpected token `('
line 6: `int main() {'
I tried looking at a lot of posts but could not resolve this. I have MS VisualStudio on Windows, but I would rather learn C++ on Ubuntu. Thanks in advance.
I think that the problem is that you're trying to execute the .cpp source file rather than the generated executable. Try running ./hello instead of ./hello.cpp, since hello is the actual executable. The errors you're currently getting are caused by the shell interpreter choking on C++ syntax, since it's trying to run it as a shell script.
Hope this helps!