468,512 Members | 1,438 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

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.
Oct 18 '06 #1
1 3282

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

Oct 18 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Victor Irzak | last post: by
reply views Thread by Ryan M. Keith | last post: by
2 posts views Thread by keit6736 | last post: by
2 posts views Thread by ricky | last post: by
6 posts views Thread by silversurfer2025 | last post: by
5 posts views Thread by lars | last post: by
6 posts views Thread by syang8 | last post: by
3 posts views Thread by Thomas Lenz | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.