String of Spaces

P

Puvendran

Hi,

I am very much a newbie in c++ and would appreciate feedback on the
following.
Due to known bug with setw() iomanipulator such that it only works
against numeric output , I need to create strings of spaces of varying
sizes.

Is there a function to do this or any easy way to detrive ?

Thanking you in advance

Puvendran
 
M

Mike Wahler

Puvendran said:
Hi,

I am very much a newbie in c++ and would appreciate feedback on the
following.
Due to known bug with setw() iomanipulator such that it only works
against numeric output , I need to create strings of spaces of varying
sizes.

Is there a function to do this or any easy way to detrive ?

std::string(how_many, ' ');

-Mike
 
R

Rob Williscroft

Puvendran wrote in
Hi,

I am very much a newbie in c++ and would appreciate feedback on the
following.
Due to known bug with setw() iomanipulator such that it only works
against numeric output , I need to create strings of spaces of varying
sizes.

Is there a function to do this or any easy way to detrive ?

#include <iostream>
#include <string>

int main()
{
std::cerr << "[" << std::string( 10, ' ' ) << "]\n";
}

HTH

Rob.
 
P

Puvendran

Rob Williscroft said:
Puvendran wrote in
Hi,

I am very much a newbie in c++ and would appreciate feedback on the
following.
Due to known bug with setw() iomanipulator such that it only works
against numeric output , I need to create strings of spaces of varying
sizes.

Is there a function to do this or any easy way to detrive ?

#include <iostream>
#include <string>

int main()
{
std::cerr << "[" << std::string( 10, ' ' ) << "]\n";
}

HTH

Rob.

Thanks for the feedback.

One thing I needed to be aware of was if you pass 0 for the length
program does not work as expected.
 

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

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,825
Members
47,371
Latest member
Brkaa

Latest Threads

Top