How to display stuff in VS Code debug console without `std::endl`?

百般思念 提交于 2020-05-30 07:51:06

问题


When debugging an app using std::cout to print something, nothing appears in the debug console (3rd tab, not external console). One of the exceptions seems to be the use of std::endl:

#include <iostream>
#include <Windows.h>
using namespace std;
int main() {
    while(true) {
        Sleep(500);
        std::cout << "Hello world!" << std::endl; // Works
    }    
}
#include <iostream>
#include <Windows.h>
using namespace std;
int main() {
    while(true) {
        Sleep(500);
        std::cout << "Hello world!\n"; // Doesn't work

        // std::cout << "Hello world!"; // Doesn't work
        // std::cout << "Hello world!" << std::flush; // Doesn't work
    }    
}

In the first example our lines appear over time, while on the second doesn't appear at all (or the console refreshes somewhere around 60 secs). I think this is a bug but I'm not sure, so what is a workaround? Maybe I have to configure something instead? I found this problem while working on something else: C++: cannot see output in VS Code while debugging

Edit

The problem is what to do when u wanna output something without a new line

来源:https://stackoverflow.com/questions/61873532/how-to-display-stuff-in-vs-code-debug-console-without-stdendl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!