简体   繁体   中英

C++ no command prompt output?

#include <iostream>


int main(int argc, char* args[]) {
    std::cout << 'hi';
    std::cout << "hello";

}

When I run this code on windows, I don't see any output. What am I doing wrong?

EDIT

I think its an issue on my machine, hence my question. I understand it could work in theory, but I want to know why it isn't working in practice. (On my windows computer)

some of the compilers will close the output windows after executing the code, so we use getchar() or getch() or system("Pause") at the end of the code. so the output windows will wait for a key press event to close the output window. so you can see your output.

std::cout << "hi"; // Double quotes required.

output-here

You should see some output with your original program, though it may not be the desired output. 26729hello

The buffers of std::cout are not being flushed to the console.

Try Running:

#include <iostream>


int main(int argc, char* args[]) {
    std::cout << "hi";
    std::cout << "hello"<<std:endl;

}

The issue is that the std::cout is storing the text "hihello" in an internal buffer, but this buffer is not being "flushed" which in this case means written to the console window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM