Get current username in C++ on Windows
Use the Win32API GetUserName function. Example: #include <windows.h> #include <Lmcons.h> char username[UNLEN+1]; DWORD username_len = UNLEN+1; GetUserName(username, &username_len);
Use the Win32API GetUserName function. Example: #include <windows.h> #include <Lmcons.h> char username[UNLEN+1]; DWORD username_len = UNLEN+1; GetUserName(username, &username_len);
The following code snippet is not complete, and contains lots of hidden assumptions and bugs. I wrote it from scratch for a university course project from mere observation, where it minimally fulfilled all the requirements. I didn’t work on it any more, because there must be libraries that would do the job way better. Here … Read more
Since you’re declaring those variables in the header file, and including the header file in each C++ file, each C++ file has its own copy of them. The usual way around this is to not declare any variables within header files. Instead, declare them in a single C++ file, and declare them as extern in … Read more
Go to Tools -> Compiler Options -> “Compiler” tab Check the checkbox labeled, “Add the following commands when calling the compiler” And add in the text entry box, “-std=c++11” or if that doesn’t work “-std=C++0x“ Should be something like that anyway, I haven’t had Dev C++ installed for many years, so I had to look … Read more
For pure C++ You can’t. C++ doesn’t even have the concept of a console. The program could be printing to a printer, outputting straight to a file, or being redirected to the input of another program for all it cares. Even if you could clear the console in C++, it would make those cases significantly … Read more