Thread: Ouput manipulator

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    52

    Ouput manipulator

    Is there (are there?) manipulators out there that will accomodate different size strings yet keep a 'centered' format.

    Here's the deal...I want to use a loop to output different variables, some of which are strings (actually, char arrays) and these are different sizes, in a perfect world all names would be the same length. Unfortunately, this is not so. Anyway I'm using basic output manipulators...ie. setw() and the like...to space items out. Is there a center align tag to implement?

    Thanks in advance to any help. I would have included code if I thought it was relevant.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    52
    O.B.T.W....

    I've looked in 3 different books for a resolution to this problem, just didn't want anybody to think I was lazy. Perhaps a little dyslexic as I couldn't find the problem....

  3. #3
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    I don't know of any formatting tags that would help you attain the desired effect (but I'm as far from an authority on the subject as you can get). I would say as an option though, that it would be relatively easy to write a function that...

    A) Counts the number of characters in your string
    B) Deducts that number from the console width (80?)
    C) Divides whatever's left by 2 giving a number X
    D) prefixes and appends your string with X number of spaces before returning it for output.

    This should in effect give you a string that will be centred so long as it prints on a new line.

  4. #4
    i wouldn't append the spaces, then if the console is 79, then it will double space it. just prefix it.

    ~Inquirer
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  5. #5
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    lol, of course, my bad Well spotted Inquirer

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    52
    I have yet to implement it, but I may be able to setf() and then right/left justify my way into readable format. If anybody else has a suggestion or better way, I'd appreciate it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Manipulator Library, just some suggestions
    By Akkernight in forum C++ Programming
    Replies: 4
    Last Post: 05-16-2009, 07:56 AM
  2. Ouput In String In Uppercase
    By lowqiumei in forum C Programming
    Replies: 7
    Last Post: 07-29-2008, 08:27 AM
  3. cout with manipulator "fixed" gives MemReadError
    By nitron in forum C++ Programming
    Replies: 0
    Last Post: 10-16-2005, 09:16 AM
  4. Expression Manipulator v0.6
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 07-01-2003, 03:49 PM
  5. Expression Manipulator v0.5 (bugs fixed, derivatives completed)
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 06-17-2003, 10:15 PM