I write small console programs in C++. I work on the 'Windows 10' operating system and through WSL I work on the 'Ubuntu' operating system. I output UTF-8 encoded text to the console (English and Cyrillic letters, Chinese hieroglyphs, emojis) using narrow char
characters via std::cout
.
When debugging programs in the 'VS Code' editor and the 'Visual Studio 2022' IDE, I need to switch the code page to UTF-8 in the debugging console beforehand. (When working with the final versions of programs in 'Windows 10', I switch the code page manually in the shell, but in 'Ubuntu' this is not required, there is UTF-8 encoding by default.)
I have a problem: in the 'VS Code' editor and in the 'Visual Studio 2022' IDE, it is difficult for me to find how to pass preliminary commands to the debugging console.
Important! I know that this can be done programmatically using Windows API functions, but I want to keep the source code cross-platform and not clutter.
I've also seen people prescribe preliminary commands for the shell 'cmd.exe' in the Windows registry, but I don't want to make changes to the registry.
I found an acceptable way in the 'VS Code' editor (I have a Microsoft extension 'ms-vscode.cpptools' installed to work with C++). In the launch.json
file I have specified an option
"console": "integratedTerminal"
Since PowerShell is used in the integrated terminal of the 'VS Code' editor, I was able to use the profile to transmit preliminary commands:
PS C:\> $profile
C:\Users\Илья\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
To a file Microsoft.PowerShell_profile.ps1
I wrote the following:
[System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8
After that, everything turned out the way I needed it:
My questions: How do I configure debugging of console programs in C++ in the 'Visual Studio 2022' IDE so that the text in UTF-8 encoding is reflected correctly in the debugging console? (Without changing the registry or changing the source code.) Is it possible to change the debugging console in the 'Visual Studio 2022' IDE with 'cmd.exe' on PowerShell? (Then I would be able to use a profile.) Is it possible to pass preliminary commands or parameters to the debugging console of 'Visual Studio 2022' IDE?