Share via

C++ Line numbers

Sid Kraft 46 Reputation points
2026-06-12T13:44:05.65+00:00

How does one get line numbers on visual studio, C++ output? with error reporting

Developer technologies | Visual Studio | Debugging
0 comments No comments

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 84,086 Reputation points
    2026-06-12T15:31:13.4233333+00:00

    for a running c++ app, the line numbers are in the .pdb file. you can use the debugger, or ship the .pdb with the .exe and use the stacktrace library, which when reporting a runtime error, will read the .pdb file to convert the address pointers to line numbers. if you are using c++ 23 then try:

    #include <iostream>
    #include <stacktrace>
    
    void main()
    {
        std::cout << std::stacktrace::current() << '\n';
    }
    
    

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-06-12T13:44:22.2233333+00:00

    To see line numbers in Visual Studio for C++ code and use them with error reporting, enable line numbers in the editor. The compiler and IDE then use these line numbers when reporting errors.

    Steps to show line numbers (C++ editor):

    1. In Visual Studio, go to Tools > Options.
    2. Navigate to Text Editor > C/C++ > General.
    3. In the Settings section, select the Line numbers checkbox.
    4. Select OK.

    Alternatively, to set line numbers for all languages:

    1. Go to Tools > Options.
    2. Expand All Settings > Languages > Defaults > General.
    3. Select the Line numbers option to enable global line numbers.

    Once enabled, line numbers appear on the left side of the editor. When a build error occurs, Visual Studio shows the file and line number in the Error List and in the build Output window. Selecting an error in the Error List jumps directly to that line. You can also press Ctrl+G and enter a line number to navigate to it.

    For C/C++ compilation itself, the compiler uses the current line number and filename when reporting errors. These values can be altered with the #line preprocessor directive, which changes what line and file names appear in error messages and in the predefined macros __LINE__ and __FILE__.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.