Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7717047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:47:10+00:00 2026-06-01T02:47:10+00:00

I have some text to write to the Windows console that I need to

  • 0

I have some text to write to the Windows console that I need to know the real width of in columns. wcswidth_l seems to be the best option on platforms that have it (though mbswidth_l() would be better since I have no desire to use wchar_t, but for some reason it doesn’t exist). But in addition to other platforms, I need something that works on Windows. Although it’s unlikely that there’s a portable solution, I don’t know of any solution at all on Windows. I think the console has an API for getting cursor position and such, so I could write the text out and check the change in position. That would be accurate I guess, but writing out extra output isn’t acceptable at all.

How does one go about getting the column width of a string or character on Windows?

Edit:

wcswidth_l returns the number of console columns used to display a string. Some characters take up one column and others, e.g. japanese characters, take up two.

As an example the ‘column width’ of “a あ” is four. ‘a’ is one, ‘ ‘ is one, and ‘あ’ is two. (Assuming the console is set up to actually display non-ascii characters that is). Also it’d be nice if the API supports strings using codepage 65001 (UTF-8).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:47:12+00:00Added an answer on June 1, 2026 at 2:47 am

    First of all, the Windows Console API is located here.

    Secondly, is the function you’re looking for GetConsoleFontSize?

    I’ll try to quickly type an example in a second.

    EDIT: Here you go. Forgive me if it there’s a small error. I actually found it was even easier. GetCurrentConsoleFont fills in a COORD structure on the way to you getting the index to pass to GetConsoleFontSize, so step saved 🙂

    #define _WIN32_WINNT 0x0501 //XP, 0x0601=windows 7
    #include <windows.h>
    
    int main()
    {
        HANDLE hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE);
    
        CONSOLE_FONT_INFO cfi;
        GetCurrentConsoleFont (hStdOutput, FALSE, &cfi);
    
        //cfi.dwFontSize.X == x size
        //cfi.dwFontSize.Y == y size
    }
    

    EDIT:

    If you don’t mind invisible output, you can use CreateConsoleScreenBuffer to pretty much have an invisible console window at your command while leaving yours unaffected. GetConsoleScreenBufferInfoEx will tell you the cursor position, at which point you can use WriteConsole to write to your buffer (invisibly), and check the cursor location again versus the number of characters actually written. Note that checking the cursor location beforehand would not require clearing the screen to use this method.

    If you cannot afford to do extra output, visible or invisible, I’m not sure there really is a possibility.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows Forms application that I need to write to the output
I have a textbox and a link button. When I write some text, select
I have some text/images that I only want to display in the normal state
I have some text i need to filter out a list of bad words
I have some text that is stored in a variable like this: <div class=foo>text
I have some text that uses Unicode punctuation, like left double quote, right single
I have some text in a UITextView, that I would like to have show
I have some text that has HTML hyper-links in it. I want to remove
I have some text that is in a file. I want to encrypt this
I have a text in an email on a windows box that looks something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.