[C++] formatting output using cout

From: Andrew Falanga (falandr_at_hp.com)
Date: 07/20/04


Date: Tue, 20 Jul 2004 08:41:26 -0600

Hi again,

I guess I must be missing something very simple because what I have is
pretty much what I found in my book and a past posting to this NG.
Anyway, I want to have this:

   Hostname: tstl3037.boi.hp.com
  Addr Type: AF_INET
    IP Addr: 15.237.95.38

What I'm getting is this:

   Hostname: tstl3037.boi.hp.com
  Addr Type: AF_INET
    IP Addr: 15.237.95.38

When the following code executes:

  std::cout << std::setw(12) << std::setiosflags(std::ios::right);
   std::cout << "Hostname: ";
   std::cout << std::setw(30) << std::setiosflags(std::ios::left);
   std::cout << he->h_name << std::endl;

   std::cout << std::setw(12) << std::setiosflags(std::ios::right);
   std::cout << "Addr Type: ";
   std::cout << std::setw(30) << std::setiosflags(std::ios::left);
   std::cout << "AF_INET" << std::endl;

   std::cout << std::setw(12) << std::setiosflags(std::ios::right);
   std::cout << "IP Addr: ";
   std::cout << std::setw(30) << std::setiosflags(std::ios::left);
   std::cout << inet_ntoa(sa.sin_addr) << std::endl;

What am I not doing right with the formatting flags, etc.? Am I just
getting my left from my right mixed up?

---------------------------------------------
Andrew R. Falanga (a non-HP employee)
Hewlett-Packard Company
11311 Chinden Blvd.
Boise, Idaho
---------------------------------------------
Please note: The e-mail address is purposely
mangled. I do not wish my account at HP to
become a spam haven.