Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No output from C++ program

Tags:

c++

cout

winpe

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. enter image description here

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?

like image 982
ddybing Avatar asked Dec 09 '25 12:12

ddybing


2 Answers

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.

like image 159
ddybing Avatar answered Dec 12 '25 04:12

ddybing


Use

    std::cout << "Hello World" << std::endl;

std::endl will flush the content and add a \n at the end of your message.

like image 25
ltabis Avatar answered Dec 12 '25 02:12

ltabis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!