How to use printf with std::string

C++23 Update We now finally have std::print as a way to use std::format for output directly: #include <print> #include <string> int main() { // … std::print(“Follow this command: {}”, myString); // … } This combines the best of both approaches. Original Answer It’s compiling because printf isn’t type safe, since it uses variable arguments in … Read more

Writing a Log file in C/C++

The standard method of logging (in my experience) is to use either the stdout or stderr streams. In C++ to use these you would need to include iostream, and use as below: #include <iostream> int main(int argc, char* argv[]) { using std::cout; using std::cerr; using std::endl; cout << “Output message” << endl; cerr << “Error … Read more

C++ vector of char array

You cannot store arrays in vectors (or in any other standard library container). The things that standard library containers store must be copyable and assignable, and arrays are neither of these. If you really need to put an array in a vector (and you probably don’t – using a vector of vectors or a vector … Read more

C++ How do I hide a console window on startup?

To literally hide/show the console window on demand, you could use the following functions: It’s possible to hide/show the console by using ShowWindow. GetConsoleWindow retrieves the window handle used by the console. IsWindowVisible can be used to checked if a window (in that case the console) is visible or not. #include <Windows.h> void HideConsole() { … Read more

tech