C++ cout printing slowly

NOTE: This experimental result is valid for MSVC. In some other implementation of library, the result will vary. printf could be (much) faster than cout. Although printf parses the format string in runtime, it requires much less function calls and actually needs small number of instruction to do a same job, comparing to cout. Here … Read more

How to print to console when using Qt

If it is good enough to print to stderr, you can use the following streams originally intended for debugging: #include<QDebug> //qInfo is qt5.5+ only. qInfo() << “C++ Style Info Message”; qInfo( “C Style Info Message” ); qDebug() << “C++ Style Debug Message”; qDebug( “C Style Debug Message” ); qWarning() << “C++ Style Warning Message”; qWarning( … Read more

Hide user input on password prompt [duplicate]

From How to Hide Text: Windows #include <iostream> #include <string> #include <windows.h> using namespace std; int main() { HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); DWORD mode = 0; GetConsoleMode(hStdin, &mode); SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT)); string s; getline(cin, s); cout << s << endl; return 0; }//main cleanup: SetConsoleMode(hStdin, mode); tcsetattr(STDIN_FILENO, TCSANOW, &oldt); Linux #include <iostream> #include <string> … Read more