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

A

alternativa

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?
 
M

mlimber

alternativa said:
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
 
M

Marcus Kwok

alternativa said:
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.
 
V

Victor Bazarov

alternativa said:
[..] 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
 
A

Alan Woodland

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top