Why is Visual Studio mangling output on subsequent runs of my program?

64 Views Asked by At

My visual studio 2022 is not working correctly. Whenever i try to output to the console, I get mangled output. I have a simple program that outputs a number to the screen 50 times by way of a for loop and this is the output of that program:

2
2
2
2
2
2
2
3
3
3
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

C:
Pr

That doesn't even make sense. If i edit my program at all, even so much as adding a newline or even adding a space and saving it, the program will run correctly, but if i run the program without modifying it, it will output something like that to the console. Also deleting the .pdb file for some reason will make the program output the expected result, but also, if I go to Build > Rebuild Solution and then run it without debugging, it outputs correctly.

Here is the code I am running for reference:

#include <iostream>

int main()
{
    int num{ 0 };

    for (int i{ 0 }; i < 50; ++i)
    {
        std::cout << num++ << '\n';
    }

    return 0;
}

This is the output of Rebuilding it then running it:

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

C:\Users\Chay\source\repos\problem\x64\Debug\problem.exe (process 19444) exited with code 0.
Press any key to close this window . . .

As you can see, that output is what is desired and expected of the code above.

I have ran this code on an online IDE, on my laptop running the same version of Visual Studio 2022 and I made a new test account on my PC and ran it on there, and the code works just fine with no issues, so its my account for some reason. Starting a new account is out of the question, I need it to work on this account. Also I have uninstalled Visual Studio and done a fresh install, did a system restore and restarted my PC. Deleting the .pdb file, modifying the program, or rebuilding it then running it is the only thing that makes it output correctly. I have also tried deleting cache files of visual studio 2022, and doing sfc /scannow from an elevated command prompt, which did find errors and fixed them, but did not resolve my issue with visual studio. I also reset VS's settings to default to no avail as well.

The only thing I can think of that started this was that I installed PVS studio to my PC today. VS never did this before today so I'm thinking that has to be it, its the only thing that makes sense. I have of course uninstalled it but the issue persists after everything.

I also tried submitting a problem report through visual studio but when I click it on the interface and it opens the web page, it keeps telling me its been disconnected from visual studio, so I'm out of luck with that.

The issue also happens in Code::Blocks so it has to be an issue with my account, I just dont know what.

1

There are 1 best solutions below

0
Chay On

Ok so I solved it. By using code blocks I saw that both VS and CB were using the windows terminal to output the results, so I deduced that it was probably the issue so I looked it up and a website said to uninstall it and that forced visual studio to default to the visual studio debugger console which works with no issues, and the standalone exe works with windows CMD console. I have no idea why the terminal program just up and decided to stop working all the sudden but that's what it was, and honestly I didn't even know the terminal was an app from the windows store until I read that website as it comes pre installed on windows 11 and defaults to it for console output, so if anyone is having those issues, that was my solution, and hopefully if anyone stumbles upon this with the same issue, that this post helps you figure it out.