By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,144 Members | 1,624 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,144 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.