467,921 Members | 1,300 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,921 developers. It's quick & easy.

problem with setw(X) and library <iomanip.h>

Hi,
I'd like to obtain an output looking as follows:

name number phone address
Caroline 233 34234 White St. 12
Anna 929043 093284 Brown St. 325

To do this (I mean to obtain constant field length for data of the same
type, even if strings are of different lengths) I tried to use setw(X)
from <iomanip.h>, so I wrote something like this:
cout << "name " << "phone " << "address" << endl;
cout << setw(15) << name << setw(10) << << number << setw(10)
phone << setw(20) << address << endl;

The problem is that the compiler returns a warning:
#warning This file includes at least one deprecated or antiquated
header. \
Please consider using one of the 32 headers found in section 17.4.1.2
of the \
C++ standard. Examples include substituting the <X> header for the
<X.h> \
header for C++ includes, or <iostream> instead of the deprecated header
\
<iostream.h>. To disable this warning use -Wno-deprecated.

What can I do to avoid it? Is there any other method for formatting the
output?

May 17 '06 #1
  • viewed: 8534
Share:
4 Replies
alternativa wrote:
Hi,
I'd like to obtain an output looking as follows:

name number phone address
Caroline 233 34234 White St. 12
Anna 929043 093284 Brown St. 325

To do this (I mean to obtain constant field length for data of the same
type, even if strings are of different lengths) I tried to use setw(X)
from <iomanip.h>, so I wrote something like this:
cout << "name " << "phone " << "address" << endl;
cout << setw(15) << name << setw(10) << << number << setw(10)
phone << setw(20) << address << endl;

The problem is that the compiler returns a warning:
#warning This file includes at least one deprecated or antiquated
header. \
Please consider using one of the 32 headers found in section 17.4.1.2
of the \
C++ standard. Examples include substituting the <X> header for the
<X.h> \
header for C++ includes, or <iostream> instead of the deprecated header
\
<iostream.h>. To disable this warning use -Wno-deprecated.

What can I do to avoid it? Is there any other method for formatting the
output?


Use <iomanip>, not <iomanip.h>. You will also either have to qualify
things as being in the std namespace or put a "using namespace std;"
after your headers in your .cpp/.cc/.C file.

Cheers! --M

May 17 '06 #2
alternativa wrote:
[..] I tried to use
setw(X) from <iomanip.h>
There is no <iomanip.h> in the Standard C++ library. Only <iomanip>.
Try it. You may need to add 'std::' to your manipulators or add some
kind of 'using' declaration or directive. Read about "std" namespace.
[...]

What can I do to avoid it?
Stop using non-standard (deprecated) headers. It's been eight years
since standard has been in place, it's time for you to learn to use
standard headers.
Is there any other method for formatting
the output?


You could use printf...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 17 '06 #3
alternativa wrote:
[snipped]
The problem is that the compiler returns a warning:
#warning This file includes at least one deprecated or antiquated
header. \
Please consider using one of the 32 headers found in section 17.4.1.2
of the \
C++ standard. Examples include substituting the <X> header for the
<X.h> \
header for C++ includes, or <iostream> instead of the deprecated header
\
<iostream.h>. To disable this warning use -Wno-deprecated.

What can I do to avoid it? Is there any other method for formatting the
output?


try:
#include <iostream>
#include <iomanip>

instead of
#include <iostream.h>
#include <iomanip.h>

Alan
May 17 '06 #4
alternativa <al***********@wp.pl> wrote:
Hi,
I'd like to obtain an output looking as follows:

name number phone address
Caroline 233 34234 White St. 12
Anna 929043 093284 Brown St. 325

To do this (I mean to obtain constant field length for data of the same
type, even if strings are of different lengths) I tried to use setw(X)
from <iomanip.h>, so I wrote something like this: [snip]
The problem is that the compiler returns a warning:
#warning This file includes at least one deprecated or antiquated
header. \
Please consider using one of the 32 headers found in section 17.4.1.2
of the \
C++ standard. Examples include substituting the <X> header for the
<X.h> \
header for C++ includes, or <iostream> instead of the deprecated header
\
<iostream.h>.


You are including the nonstandard <iomanip.h>. Instead, try #including
<iomanip> (no .h on the end). Note that a common convention for these
headers is that <iomanip.h> had symbols in the global namespace but
<iomanip> has them in namespace std, so you may need to:

1. Fully qualify the names (e.g., std::setw(10) instead of setw(10))
2. Use using-declarations (e.g., using std::setw;)
3. Use a using-directive (e.g., using namespace std)

I put these in my personal preference order, but see the FAQ for more
information.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
May 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Donald Firesmith | last post: by
2 posts views Thread by rupert | last post: by
3 posts views Thread by ajay2552 | last post: by
2 posts views Thread by Markus Dehmann | last post: by
6 posts views Thread by Bernd Gaertner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.