how to put tab characters into ostream?



 DEVELOP > c-Plus-Plus > how to put tab characters into ostream?

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "auditory"
Date: 18 Oct 2006 03:26:04 AM
Object: how to put tab characters into ostream?
i am working with the program which generates
c language source code.
i implemented function adding indentation tabs to each line like
std::string tabcharcter(int depth)
{
string tab;
for(int i=0;i<depth;i++) tab+="\t";
return tab;
}
in some function
{
....
ostream os;
while(..)
{
os << tabcharcter(3);
os << string_line << endl;
}
....
}
is there any better way for this?
like some output manipulater, or,
automatic way to add n tabs after new line character added.
.

User: "Earl Purple"

Title: Re: how to put tab characters into ostream? 18 Oct 2006 03:40:12 AM
auditory wrote:

i am working with the program which generates
c language source code.

i implemented function adding indentation tabs to each line like

std::string tabcharcter(int depth)
{
string tab;
for(int i=0;i<depth;i++) tab+="\t";
return tab;
}

There is no need for your tabcharacter function as you can create a
string with its constructor that takes a size and a character. Note it
takes the size first.

in some function
{
...
ostream os;

while(..)
{
os << tabcharcter(3);
os << string_line << endl;
}
...
}
is there any better way for this?
like some output manipulater, or,
automatic way to add n tabs after new line character added.

I don't know what is string_line but if you are iterating through
vector<string> then you can make use of ostream_iterator's delimiter
something in the nature of:
std::string delim( len, '\t' );
std::copy
(
lines.begin(), lines,end(),
std::ostream_iterator< std::string >( os, delim.c_str() )
);
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER