[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

stream problemer



Hej.

Jeg har et program der skal udskrive enten til cout eller til en fil, alt
efter om der er specificeret en output fil.

fx.

void Udskriv(ostream& o, char* p) { o << p;}

int main()
{
   if (outputfile) ofstream fo("outout");
  
   :
 
   if (!outputfile) Udskriv(cout,"test");
               else Udskriv(fo,"test");
}

Dette virker, men hver gang jeg skal udskrive skal jeg lave en if sætning, 
hvilket er dumt fordi der kun er forskel på første argumentet. 

Det jeg gerne vil lave i starten er en
ostream& out;
ofstream fo;

if (!outputfile) out=cout;
            else {
                      fo.open(...)
                      out=fo;
                   }

og så bare skrive

Udskriv(out,"whatever");

Men det syntes at at være besværligt at tildele cout til en vilkårlig
ostream. Enten findes operator= ikke ellers er der klasse mismatch.

Nogle forslag?
-- 
  Mvh. Carsten Svaneborg


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *