Thread: Word Wrap

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    1

    Word Wrap

    Hi

    I am just starting to learn C++. Most of the problems I have encountered have been resolved. However, there is one problem which I cannot find an answer for. I am sending large chunks of text to a console window, but it cuts up words instead of moving the whole word to the next line. Is there any way that word-wrap can be enabled through C++ code?

    Thanks in advance!

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Kind of.

    In windows you can use the GetConsoleScreenBufferInfo() to get the buffer width and then basically cut your strings at the last word before that many characters and place a newline in manually.

    You can find out more about Win32 commands here or here.
    Sent from my iPadŽ

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Yeah... You need to scan thru you text in a loop, looking for spaces. You can search
    for ' ' or a value 32, which is an ASCII space.

    Each time you find a space, you test: Will the string fit? If it will fit, you continue to the next space.

    When you finally go to far, you can either scan backwards to the previous space, or you can continuously keep-track of the previous-space position.
    Last edited by DougDbug; 02-27-2006 at 03:12 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing to a file with word wrap?
    By Djanvk in forum C++ Programming
    Replies: 1
    Last Post: 08-17-2008, 05:09 AM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  3. Word Wrap
    By sethjackson in forum Windows Programming
    Replies: 4
    Last Post: 09-21-2005, 04:35 PM
  4. Wrong Output
    By egomaster69 in forum C Programming
    Replies: 7
    Last Post: 01-28-2005, 06:44 PM
  5. Word Wrap
    By osal in forum Windows Programming
    Replies: 4
    Last Post: 07-02-2004, 11:16 AM