delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/30/14:30:41

From: Rodeo Red <rodeored AT netstep DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: missing <ostream>
Date: Sun, 30 Jan 2000 10:13:23 -0500
Organization: Church of Evangelical Environmental Extremism
Lines: 144
Message-ID: <E1D0A4CADBAC5FC0.8E50956E4A580C85.79A2A03D8020D9D0@lp.airnews.net>
X-Orig-Message-ID: <38945513 DOT 3D8E7D5F AT netstep DOT net>
References: <A07BFA639570509F DOT 80D3BEF731426AC0 DOT B418A6AEF5DF1D20 AT lp DOT airnews DOT net> <38910E6A DOT DF22D15A AT americasm10 DOT nt DOT com> <389169e4$1 AT news DOT uni-bielefeld DOT de>
Abuse-Reports-To: support at netstep.net to report improper postings
NNTP-Proxy-Relay: library2.airnews.net
NNTP-Posting-Time: Sun Jan 30 09:10:25 2000
NNTP-Posting-Host: !\DtK-@[.=N"J8s (Encoded at Airnews!)
Mime-Version: 1.0
X-Mailer: Mozilla 4.7 [en] (Win98; I)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Manni Heumann wrote:
> 
> Standard headers in C++ don't come with a suffix.
> libgpp should not be necessary for C++, you only need it to compile legacy
> code (e.g. to compile programs that use the String class).
> 
> But what sort of functionality should <ostream> contain?

It opens a file for output. from my text books it seems to be part of
the standard library. 
AFAIK, that measn it should be in djgpp and I probably lost it.  It
would be nice if someone could simply verify whether or not <ostream is
supposed to be in dgjpp or not. 

 
> AFAIK once you include <fstream> you don't have to worry about the subclasses.
> Try to change the #include lines below with this:
> #include <fstream>
> #include <string>
> 
> I bet it will compile then.

Those headers are already included. If I just erase "#include <ostream>"
the program compiles but doesn't work correctly. I get a message telling
me a file failed to open.  
 
The program is pretty short, so here it is: I'm trying to learn how to
open and manipulate files:  

// liner.cpp
// Example of reading and writing text files and
// defining personal iomanipulators

#include <iostream>
#include <fstream>
#include <ostream>
#include <string>

#ifndef MAXPATHLEN
  const int MAXPATHLEN = 255;
#endif

const std::string PROG = "liner";
const int  MAJOR  = 0;
const int  MINOR  = 1;

std::ostream &
Prog ( std::ostream & stream )
{
   stream << "\n"
          << PROG << " Version: " << MAJOR << "." << MINOR 
          << std::endl;
   return (stream);
}

std::ostream &
Sepline ( std::ostream & stream )
{
   stream <<
"------------------------------------------------------------------"
          << std::endl;
   return (stream);
}

int
main ( int argc, char * argv[] )
{
    char inputfile[MAXPATHLEN] = {0};
    char outputfile[MAXPATHLEN] = {0};

    if ( argc < 2 )
    {
        std::cerr << Prog << Sepline
             << "Syntax: " << PROG << " inputfile <outputfile>" <<
std::endl;
        return(1);
    }

    strcpy ( inputfile, argv[1] );

    std::ifstream input( inputfile, std::ios::in );
    std::ofstream output;
  
    if ( input.is_open() == false )
    {
        std::cerr << Prog << Sepline
             << "Failed to open: " << inputfile << std::endl;
        return(2);
    }

    std::cout << Prog;

    if ( argv[2] )
    {
        strcpy ( outputfile, argv[2] );
        output.open ( outputfile, std::ios::out );
        if ( output.bad() )
        {
            std::cerr << Sepline
                 << "Failed to open: " << outputfile << std::endl;
            return(3);
        }
        else
        {
            std::cout << "Output File: " << outputfile << std::endl;
            output << Prog;
            output << Sepline;
        }
    }

    std::cout << Sepline;

    char buffer[MAXPATHLEN] = {0};
    int counter = 0;
    int bytes = 0;

    while ( !input.eof() )
    {
        input.getline ( buffer, MAXPATHLEN );
        bytes += strlen(buffer);
        counter++;
        std::cout << counter << "\t| " << buffer << std::endl;
        if ( output.good() )
        {
          output << counter << "\t| " << buffer << std::endl;
        }
    }

    std::cout << Sepline;
    std::cout << "Lines in file: " << counter << std::endl;
    std::cout << "Bytes in file: " << bytes << std::endl;

    if ( output.good() )
    {
      output << Sepline;
      output << "Lines in file: " << counter << std::endl;
      output << "Bytes in file: " << bytes << std::endl;
    }

    output.close();
    input.close();

    return(0);
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019