 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
auditory Guest
|
Posted: Wed Oct 18, 2006 9:10 am Post subject: 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. |
|
| Back to top |
|
 |
Earl Purple Guest
|
Posted: Wed Oct 18, 2006 9:10 am Post subject: Re: how to put tab characters into ostream? |
|
|
auditory wrote:
| Quote: | 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.
| Quote: | 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() )
); |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|