www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/12/23/23:50:31

Message-ID: <000b01c06d64$fce076e0$8cb13cd8@mainsystem>
From: cody1 AT ktsnet DOT com (cody1)
To: <djgpp AT delorie DOT com>
Subject: please help me
Date: Sat, 23 Dec 2000 22:49:55 -0600
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
Reply-To: djgpp AT delorie DOT com

This is a multi-part message in MIME format.

------=_NextPart_000_0007_01C06D32.AB6E5160
Content-Type: multipart/alternative;
	boundary="----=_NextPart_001_0008_01C06D32.AB6E5160"


------=_NextPart_001_0008_01C06D32.AB6E5160
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I recently downloaded your wonderful c++ compiler and I absolutely love =
it.  I have one important question though that I really need help with.  =
I have some header and cpp files from school that allow me to use =
apstrings, apvectors, and apmatrices, which are just easier ways to =
manipulate strings, arrays, and multi-dimensional arrays.  However, =
whenever I tried using these with your compiler, I got the following =
error:
this one is what happened when I tried to compile apvector.cpp from the =
command line:

" In file included from apvector.cpp:17:
c:/djgpp/lang/cxx/apvector.h:127: apvector.cpp: No such file or =
directory (ENOENT)"

I tried using apvector.h without recompiling it, but to no avail.  =
Besides your compiler, I use Borland c++ 3.0, and it works perfectly in =
it with absolutely no errors at all, but when I try to use it with =
djgpp, it's completely filled with errors everywhere.  Please help me, =
as I look forward to using your great compiler (and the world of 32-bit =
applications), but I can't do without these libraries.  I have included =
the apstring.h and apstring.cpp files to allow you to see for yourself =
(if you have time) what's wrong with them.  Thank you for your time and =
consideration.

                                                                         =
               Sincerely,
                                                                         =
               Cody May

------=_NextPart_001_0008_01C06D32.AB6E5160
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I recently downloaded your wonderful =
c++ compiler=20
and I absolutely love it.&nbsp; I have one important question though =
that I=20
really need help with.&nbsp; I have some header and cpp files from =
school that=20
allow me to use apstrings, apvectors, and apmatrices, which are just =
easier ways=20
to manipulate strings, arrays, and multi-dimensional arrays.&nbsp; =
However,=20
whenever I tried using these with your compiler, I got the following=20
error:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>this one is what happened when I tried =
to compile=20
apvector.cpp from the command line:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>" In file included from apvector.cpp:17:</DIV>
<DIV>c:/djgpp/lang/cxx/apvector.h:127: apvector.cpp: No such file or =
directory=20
(ENOENT)"</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I tried using apvector.h without =
recompiling it,=20
but to no avail.&nbsp; Besides your compiler, I use Borland c++ 3.0, and =
it=20
works perfectly in it with absolutely no errors at all, but when I try =
to use it=20
with djgpp, it's completely filled with errors everywhere.&nbsp; Please =
help me,=20
as I look forward to using your great compiler (and the world of 32-bit=20
applications), but I can't do without these libraries.&nbsp; I have =
included the=20
apstring.h and apstring.cpp files to allow you to see for yourself (if =
you have=20
time) what's wrong with them.&nbsp; Thank you for your time and=20
consideration.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
Sincerely,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp; Cody=20
May</FONT></DIV></BODY></HTML>

------=_NextPart_001_0008_01C06D32.AB6E5160--

------=_NextPart_000_0007_01C06D32.AB6E5160
Content-Type: application/octet-stream;
	name="APSTRING.H"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="APSTRING.H"

#ifndef _APSTRING_H
#define _APSTRING_H

#include <iostream.h>
#include "BOOL.H"


// *******************************************************************
//  APCS string class
//
//  string class consistent with a subset of the standard C++ string =
class
//  as defined in the draft ANSI standard
// *******************************************************************

extern const int npos;  // used to indicate not a position in the string

class apstring
{
  public:

  // constructors/destructor

    apstring( );                         // construct empty string ""
    apstring( const char * s );          // construct from string =
literal
    apstring( const apstring & str );      // copy constructor
    ~apstring( );                        // destructor

  // assignment

    const apstring & operator =3D ( const apstring & str ); // assign =
str
    const apstring & operator =3D ( const char * s );       // assign s
    const apstring & operator =3D ( char ch );              // assign ch

  // accessors

    int    length( )                  const;    // number of chars
    int    find( const apstring & str ) const;  // index of first =
occurrence of str
    int    find( char ch )            const;    // index of first =
occurrence of ch
    apstring substr( int pos, int len ) const;    // substring of len =
chars
						// starting at pos
    const char * c_str( )             const;    // explicit conversion =
to char *

  // indexing

    char   operator[ ]( int k )       const;    // range-checked =
indexing
    char & operator[ ]( int k );                // range-checked =
indexing

  // modifiers

    const apstring & operator +=3D ( const apstring & str );// append =
str
    const apstring & operator +=3D ( char ch );            // append =
char


  private:
      int myLength;                     // length of string (# of =
characters)
      int myCapacity;                   // capacity of string
      char * myCstring;                 // storage for characters
};

// The following free (non-member) functions operate on strings
//
// I/O functions

ostream & operator << ( ostream & os, const apstring & str );
istream & operator >> ( istream & is, apstring & str );
istream & getline( istream & is, apstring & str );

// comparison operators:

bool operator =3D=3D ( const apstring & lhs, const apstring & rhs );
bool operator !=3D ( const apstring & lhs, const apstring & rhs );
bool operator <  ( const apstring & lhs, const apstring & rhs );
bool operator <=3D ( const apstring & lhs, const apstring & rhs );
bool operator >  ( const apstring & lhs, const apstring & rhs );
bool operator >=3D ( const apstring & lhs, const apstring & rhs );

// concatenation operator +

apstring operator + ( const apstring & lhs, const apstring & rhs );
apstring operator + ( char ch, const apstring & str );
apstring operator + ( const apstring & str, char ch );

// *******************************************************************
// Specifications for string functions
//
// Any violation of a function's precondition will result in an error
// message followed by a call to abort.
//
// constructors / destructor
//
// string( )
//    postcondition: string is empty
//
// string( const char * s )
//    description:   constructs a string object from a literal string
//                   such as "abcd"
//    precondition:  s is '\0'-terminated string as used in C
//    postcondition: copy of s has been constructed
//
// string( const string & str )
//    description:   copy constructor
//    postcondition: copy of str has been constructed
//
// ~string( );
//    description:   destructor
//    postcondition: string is destroyed
//
// assignment
//
// string & operator =3D ( const string & rhs )
//    postcondition: normal assignment via copying has been performed
//
// string & operator =3D ( const char * s )
//    description:   assignment from literal string such as "abcd"
//    precondition:  s is '\0'-terminated string as used in C
//    postcondition: assignment via copying of s has been performed
//
// string & operator =3D ( char ch )
//    description:   assignment from character as though single char =
string
//    postcondition: assignment of one-character string has been =
performed
//
// accessors
//
// int length( ) const;
//    postcondition: returns # of chars in string
//
// int find( const string & str)  const;
//    description:   find the first occurrence of the string str within =
this
//                   string and return the index of the first character. =
 If
//                   str does not occur in this string, then return =
npos.
//    precondition:  this string represents c0, c1, ..., c(n-1)
//                   str represents s0, s1, ...,s(m-1)
//    postcondition: if s0 =3D=3D ck0, s1 =3D=3D ck1, ..., s(m-1) =3D=3D =
ck(m-1) and
//                   there is no j < k0 such that s0 =3D cj, ...., sm =
=3D=3D c(j+m-1),
//                   then returns k0;
//                   otherwise returns npos
//
// int find( char ch ) const;
//    description:   finds the first occurrence of the character ch =
within this
//                   string and returns the index.  If ch does not occur =
in this
//                   string, then returns npos.
//    precondition:  this string represents c0, c1, ..., c(n-1)
//    postcondition: if ch =3D=3D ck, and there is no j < k such that ch =
=3D=3D cj
//                   then returns k;
//                   otherwise returns npos
//
// string substr( int pos, int len ) const;
//    description:   extract and return the substring of length len =
starting
//                   at index pos
//    precondition:  this string represents c0, c1, ..., c(n-1)
//                         0 <=3D pos <=3D pos + len - 1 < n.
//    postcondition: returns the string that represents
//                   c(pos), c(pos+1), ..., c(pos+len-1)
//
// const char * c_str( ) const;
//    description:   convert string into a '\0'-terminated string as
//                   used in C for use with functions
//                   that have '\0'-terminated string parameters.
//    postcondition: returns the equivalent '\0'-terminated string
//
// indexing
//
// char operator [ ]( int k ) const;
//    precondition:  0 <=3D k < length()
//    postcondition: returns copy of the kth character
//
// char & operator [ ]( int k )
//    precondition:  0 <=3D k < length()
//    postcondition: returns reference to the kth character
//
// modifiers
//
// const string & operator +=3D ( const string & str )
//    postcondition: concatenates a copy of str onto this string
//
// const string & operator +=3D ( char ch )
//    postcondition: concatenates a copy of ch onto this string
//
//
// non-member functions
//
// ostream & operator << ( ostream & os, const string & str)
//    postcondition: str is written to output stream os
//
// istream & operator >> ( istream & is, string & str )
//    precondition:  input stream is open for reading
//    postcondition: the next string from input stream is has been read
//                   and stored in str
//
// istream & getline( istream & is, string & str )
//    description:   reads a line from input stream is into the string =
str
//    precondition:  input stream is open for reading
//    postcondition: chars from input stream is up to '\n' have been =
read
//                   and stored in str; the '\n' has been read but not =
stored
//
// string operator + ( const string & lhs, const string & rhs )
//    postcondition: returns concatenation of lhs with rhs
//
// string operator + ( char ch, const string & str )
//    postcondition: returns concatenation of ch with str
//
// string operator + ( const string & str, char ch )
//    postcondition: returns concatenation of str with ch
//
//***************************************************************

#include "apstring.cpp"
#endif


------=_NextPart_000_0007_01C06D32.AB6E5160
Content-Type: application/octet-stream;
	name="APSTRING.CPP"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="APSTRING.CPP"

// *******************************************************************
//  Last Revised: January 13, 1998,  <=3D and >=3D redefined using ! and =
<
//                                   operator +=3D now takes constant
//                                   amortized time for adding one char
//
//  APCS string class  IMPLEMENTATION
//
//  see apstring.h for complete documentation of functions
//
//  string class consistent with a subset of the standard C++ string =
class
//  as defined in the draft ANSI standard
// *******************************************************************

#include <string.h>
#include <assert.h>
#include "apstring.h"

const int npos =3D -1;
const int MAX_LENGTH =3D 1024;        // largest size string for input

apstring::apstring()
// postcondition: string is empty
{
    myLength =3D 0;
    myCapacity =3D 1;
    myCstring =3D new char[myCapacity];
    myCstring[0] =3D '\0';           // make c-style string zero length
}


apstring::apstring(const char * s)
//description:   constructs a string object from a literal string
//               such as "abcd"
//precondition:  s is '\0'-terminated string as used in C
//postcondition: copy of s has been constructed
{
    assert (s !=3D 0);               // C-string not NULL?

    myLength =3D strlen(s);
    myCapacity =3D myLength + 1;      // make room for '\0'
    myCstring =3D new char[myCapacity];
    strcpy(myCstring,s);
}

apstring::apstring(const apstring & str)
//description:   copy constructor
//postcondition: copy of str has been constructed
{
    myLength =3D str.length();
    myCapacity =3D myLength + 1;
    myCstring =3D new char[myCapacity];
    strcpy(myCstring,str.myCstring);
}

apstring::~apstring()
//description:   destructor
//postcondition: string is destroyed
{
    delete[] myCstring;                // free memory
}

const apstring& apstring::operator =3D(const apstring & rhs)
//postcondition: normal assignment via copying has been performed
{
    if (this !=3D &rhs)                             // check aliasing
    {
        if (myCapacity < rhs.length() + 1)        // more memory needed?
        {
            delete[] myCstring;                   // delete old string
            myCapacity =3D rhs.length() + 1;        // add 1 for '\0'
            myCstring =3D new char[myCapacity];
        }
        myLength =3D rhs.length();
        strcpy(myCstring,rhs.myCstring);
    }
    return *this;
}


const apstring& apstring::operator =3D (const char * s)
//description:   assignment from literal string such as "abcd"
//precondition:  s is '\0'-terminated string as used in C
//postcondition: assignment via copying of s has been performed
{

    int len =3D 0;                         // length of newly =
constructed string
    assert(s !=3D 0);                      // make sure s non-NULL
    len =3D strlen(s); // # of characters in string

    // free old string if necessary

    if (myCapacity < len + 1)
    {
   delete[] myCstring;  // delete old string
   myCapacity =3D len + 1;   // add 1 for '\0'
   myCstring =3D new char[myCapacity];
    }
    myLength =3D len;
    strcpy(myCstring,s);
    return *this;
}

const apstring& apstring::operator =3D (char ch)
//description:   assignment from character as though single char string
//postcondition: assignment of one-character string has been performed
{
    if (myCapacity < 2)
    {
        delete [] myCstring;
        myCapacity =3D 2;
        myCstring =3D new char[myCapacity];
    }
    myLength =3D 1;
    myCstring[0] =3D ch;  // make string one character long
    myCstring[1] =3D '\0';
    return *this;
}

int apstring::length( ) const
//postcondition: returns # of chars in string
{
    return myLength;
}

const char * apstring::c_str() const
//description:   convert string into a '\0'-terminated string as
//               used in C for use with functions
//               that have '\0'-terminated string parameters.
//postcondition: returns the equivalent '\0'-terminated string
{
    return myCstring;
}

char& apstring::operator[](int k)
// precondition:  0 <=3D k < length()
// postcondition: returns copy of the kth character
// note:          if this reference is used to write a '\0'
//                subsequent results are undefined
{
    if (k < 0 || myLength <=3D k)
    {
        cerr << "index out of range: " << k << " string: " << myCstring
            << endl;
        assert(0 <=3D k && k < myLength);
    }
    return myCstring[k];
}

char apstring::operator[](int k) const
// precondition:  0 <=3D k < length()
// postcondition: returns copy of the kth character
{
    if (k < 0 || myLength <=3D k)
    {
        cerr << "index out of range: " << k << " string: " << myCstring
            << endl;
        assert(0 <=3D k && k < myLength);
    }
    return myCstring[k];
}

ostream& operator <<(ostream & os, const apstring & str)
//postcondition: str is written to output stream os
{
    return os << str.c_str();
}

istream& operator >>(istream & is, apstring & str)
//precondition:  input stream is open for reading
//postcondition: the next string from input stream is has been read
//               and stored in str
{
    char buf[MAX_LENGTH];
    is >> buf;
    str =3D buf;
    return is;
}


istream & getline(istream & is, apstring & str)
//description:   reads a line from input stream is into the string str
//precondition:  input stream is open for reading
//postcondition: chars from input stream is up to '\n' have been read
{
    char buf[MAX_LENGTH];
    is.getline(buf,MAX_LENGTH);
    str =3D buf;
    return is;
}

const apstring& apstring::operator +=3D(const apstring & str)
//postcondition: concatenates a copy of str onto this string
{

    apstring copystring(str);         // copy to avoid aliasing problems

    int newLength =3D length() + str.length(); // self + added string
    int lastLocation =3D length();      // index of '\0'

    // check to see if local buffer not big enough
    if (newLength >=3D myCapacity)
    {
        myCapacity =3D newLength + 1;
   if (str.length() =3D=3D 1)  // special case for catenating one char
   {                       // make room for future catenations
       myCapacity *=3D 2;
   }
        char * newBuffer =3D new char[myCapacity];
        strcpy(newBuffer,myCstring); // copy into new buffer
        delete [] myCstring;       // delete old string
        myCstring =3D newBuffer;
    }

    // now catenate str (copystring) to end of myCstring
    strcpy(myCstring+lastLocation,copystring.c_str() );
    myLength =3D newLength;           // update information

    return *this;
}

const apstring & apstring::operator +=3D ( char ch )
// postcondition: concatenates a copy of ch onto this string
{
    apstring temp;   // make string equivalent of ch
    temp =3D ch;
    *this +=3D temp;
    return *this;
}

apstring operator +(const apstring & lhs, const apstring & rhs)
// postcondition: returns concatenation of lhs with rhs
{
    apstring result(lhs);  // copies lhs to result
    result +=3D rhs;   // catenate rhs
    return result;   // returns a copy of result
}

apstring operator + ( char ch, const apstring & str )
// postcondition: returns concatenation of ch with str
{
    apstring result; // make string equivalent of ch
    result =3D ch;
    result +=3D str;
    return result;
}

apstring operator + ( const apstring & str, char ch )
// postcondition: returns concatenation of str with ch
{
    apstring result(str);
    result +=3D ch;
    return result;
}


apstring apstring::substr(int pos, int len) const
//description:   extract and return the substring of length len starting
//               at index pos
//precondition:  this string represents c0, c1, ..., c(n-1)
//               0 <=3D pos <=3D pos + len - 1 < n.
//postcondition: returns the string that represents
//               c(pos), c(pos+1), ..., c(pos+len-1)
//
{
    if (pos < 0)                       // start at front when pos < 0
    {
       pos =3D 0;
    }

    if (pos >=3D myLength) return "";     // empty string

    int lastIndex =3D pos + len - 1;      // last char's index (to copy)
    if (lastIndex >=3D myLength)          // off end of string?
    {
        lastIndex =3D myLength-1;
    }

    apstring result(*this);               // make sure enough space =
allocated

    int j,k;
    for(j=3D0,k=3Dpos; k <=3D lastIndex; j++,k++)
    {
        result.myCstring[j] =3D myCstring[k];
    }
    result.myCstring[j] =3D '\0';         // properly terminate C-string
    result.myLength =3D j;                // record length properly
    return result;
}

int apstring::find(const apstring & str)  const
//description:   find the first occurrence of the string str within this
//               string and return the index of the first character.  If
//               str does not occur in this string, then return npos.
//precondition:  this string represents c0, c1, ..., c(n-1)
//               str represents s0, s1, ...,s(m-1)
//postcondition: if s0 =3D=3D ck0, s1 =3D=3D ck1, ..., s(m-1) =3D=3D =
ck(m-1) and
//               there is no j < k0 such that s0 =3D cj, ...., sm =3D=3D =
c(j+m-1),
//               then returns k0;
//               otherwise returns npos
{
    int len =3D str.length();
    int lastIndex =3D length() - len;
    int k;
    for(k=3D0; k <=3D lastIndex; k++)
    {
        if (strncmp(myCstring + k,str.c_str(),len) =3D=3D 0) return k;
    }
    return npos;
}

int apstring::find( char ch ) const
// description:   finds the first occurrence of the character ch within =
this
//                string and returns the index.  If ch does not occur in =
this
//                string, then returns npos.
// precondition:  this string represents c0, c1, ..., c(n-1)
// postcondition: if ch =3D=3D ck, and there is no j < k such that ch =
=3D=3D cj
//                then returns k;
//                otherwise returns npos
{
    int k;
    for(k=3D0; k < myLength; k++)
    {
        if (myCstring[k] =3D=3D ch)
        {
       return k;
   }
    }
    return npos;
}


bool operator =3D=3D ( const apstring & lhs, const apstring & rhs )
{
    return strcmp(lhs.c_str(), rhs.c_str()) =3D=3D 0;
}

bool operator !=3D ( const apstring & lhs, const apstring & rhs )
{
    return ! (lhs =3D=3D rhs);
}

bool operator <  ( const apstring & lhs, const apstring & rhs )
{
    return strcmp(lhs.c_str(), rhs.c_str()) < 0;
}

bool operator <=3D ( const apstring & lhs, const apstring & rhs )
{
    return !( rhs < lhs );
}
bool operator >  ( const apstring & lhs, const apstring & rhs )
{
    return rhs < lhs;
}

bool operator >=3D ( const apstring & lhs, const apstring & rhs )
{
    return ! ( lhs < rhs );
}

------=_NextPart_000_0007_01C06D32.AB6E5160--

- Raw text -


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