Thread: tabular console output

  1. #1
    Registered User
    Join Date
    Nov 2006

    tabular console output


    is there anything better than
    ? Because it fails if the size of some table entrys differ:

    #include <iostream>
    #include <map>
    int main()
    	std::map<const char*, int> map;
    	map["a"] = 1;
    	map["bbbbbbbbbbbb"] = 2;
    	map["ccccc"] = 3;
    	for (std::map<const char*, int>::const_iterator citer = map.begin(); citer!=map.end(); ++citer)
    		std::cout << citer->first << "\t\t\t\t\t" << citer->second << "\n";

    ccccc                                   3
    bbbbbbbbbbbb                                    2
    a                                       1
    Only ways I see is to take the current size of the field into account to determine the number of \t needed.

    Thank you!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    use "setw()" to set the width of the respective fields.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get the console output
    By outlawbt in forum Windows Programming
    Replies: 2
    Last Post: 03-19-2008, 02:25 PM
  2. redirect console output to a String?
    By TwistedMetal in forum C Programming
    Replies: 10
    Last Post: 02-26-2008, 02:54 PM
  3. Help with Console output
    By JeremyCAFE in forum C++ Programming
    Replies: 4
    Last Post: 12-20-2005, 10:36 AM
  4. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  5. Redirecting console output
    By _hannes in forum Windows Programming
    Replies: 3
    Last Post: 11-04-2004, 04:51 AM