| 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() )
);
.
|
|
|
|

|
Related Articles |
|
|