No output from C++ program - c++

First of all, sorry if this is in the wrong category, as I am not sure what the cause of this problem is.
For educational purposes I have created a small "Hello World" application
#include <iostream>
int main() {
std::cout << "Hello World\n";
return 0;
}
I have tried compiling it with both Visual Studio as well as MINGW-64(g++ -m64 main.cpp), as a 64-bit application. It runs perfectly on my Windows computer, but when I try to run it within the latest Windows PE it doesn't print out any thing. I have also tried with std::cin so that the program doesn't stop right away, but the same thing happens - no output and no error.
I know WinPE is very limited in terms of included libraries and subsystems, but I really thought that this simple Hello World app would run. The WinPE environment is 64-bit, that 's why I am compiling as 64-bit
Any ideas where I should start?

I found the actual problem. I didn't compile the application statically which caused it to rely on dependencies not found in WinPE. I re-compiled it using the '-static' flag and it now works as expected on both WinPE and desktop versions of Windows.

Use
std::cout << "Hello World" << std::endl;
std::endl will flush the content and add a \n at the end of your message.

Related

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

No output on std::cout while outside of IDE

I have this well known c++ program in my Visual Studio 2015 Prof:
#include <iostream>
int main(int argc, char* argv[]) {
std::cout << "Hello World!" << std::endl;
return 0;
}
As expected, it shows "Hello World!" if I hit Ctrl+F5. However, if I go to the directory within an cmd.exe and execute the HelloWorld.exe file, it doesn't show anything as output, but does quit (I can type in again).
According to a similar question I checked the settings of the project but I did not need to change anything, the Configuration Properties -> Linker -> System -> SubSystem already is at Console (/SUBSYSTEM:CONSOLE).
Flushing the std::cout also didn't help anything. It is reproducable on every freshly created project of VS2015 on my Win 7 64-bit machine and seems to be presistent after rebooting.
What is wrong with my IDE / settings?
After the hint of #Scheff I threw the exe file into "Dependency Walker". It gave me a missing UCRTBASED.DLL and lots of second and third level missing dlls (I think this is usually the case on every application?).
I somehow think my (recently installed) anti virus did interfere with that, because it shows some messages in the log regarding my HelloWorld.exe.
However, deinstalling anti virus and restarting machine did the trick. I can finally see Hello World! on cmd.exe.

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.

OS X 10.6.4 + Eclipse 3.5 + latest CDT not outputting cout/printf to console

I spend most of my time in Eclipse these days, so I thought I would check out what Eclipse's C++ support was like (I usually use Xcode on Mac and Visual Studio for Windows).
I found the CDT package for Eclipse 3.5, so I installed it.
Everything installed properly and the default C++ "Hello World" project compiled nicely, however for the life of me I can't get any application output piped to the console. I've tried everything, and searched around for solutions, but it seems I'm not the only one. Most have trouble in Windows, but I haven't seen a lot of issues with OS X.
Of course, if I run the compiled output in a bash shell, it displays output properly.
This is how simple the default app is:
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
printf("Hello world");
return 0;
}
Any ideas?
Cheers,
Shane
Just tried this in Helios 3.6 and it works. Must be a 3.5 problem.