C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to put tab characters into ostream?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
auditory
Guest





PostPosted: Wed Oct 18, 2006 9:10 am    Post subject: how to put tab characters into ostream? Reply with 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;
}

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





PostPosted: Wed Oct 18, 2006 9:10 am    Post subject: Re: how to put tab characters into ostream? Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.