-
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!
-
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.
-
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.