Hey, I am in the process of writing a program that stores a integer entry into an array where each element in that array directly corresponds to a date on the calendar for that month. I think I have my code working, or at least almost working. My problem comes when I am trying to include apstring.h into it. I get the following errors:

Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int apstring.h 70

Error 2 error C2556: 'std::ostream &operator <<(std::ostream &,const apstring &)' : overloaded function differs only by return type from 'int &operator <<(std::ostream &,const apstring &)' apstring.cpp 166

Error 3 error C2371: 'operator <<' : redefinition; different basic types c:\documents and settings\hooker\desktop\logbook\apstring.cpp 166


I have tried to understand what is up and have done several google searches to try to figure this out but have had no luck... In my efforts I actually went from 22 errors to just these three but now I am stuck... My code is attached and I am using VS 2005. Test1.cpp is the test program to test my work.

Thanks for the help!

Attachments
// *******************************************************************
//  Revised: April 4, 2006,  <= and >= redefined using ! and <
//                              operator += now takes constant
//                              amortized time for adding one char
//
//  Revised: April 4, 2006, replaced assert with exit: operator[]
//                              changed operator >> and getline
//                              so no limit on size of strings read
//
//  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 <stdlib.h>
#include <ctype.h>
#include "apstring.h"

const int npos = -1;

apstring::apstring()
// postcondition: string is empty
{
    myLength = 0;
    myCapacity = 1;
    myCstring = new char[myCapacity];
    myCstring[0] = '\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 != 0);               // C-string not NULL?
    myLength = strlen(s);
    myCapacity = myLength + 1;      // make room for '\0'
    myCstring = new char[myCapacity];
    strcpy(myCstring,s);
}

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

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

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

const apstring& apstring::operator = (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 = 0;                         // length of newly constructed string
    assert(s != 0);                      // make sure s non-NULL
    len = strlen(s); // # of characters in string
    // free old string if necessary
    if (myCapacity < len + 1)
    {
	   delete[] myCstring;  // delete old string
	   myCapacity = len + 1;   // add 1 for '\0'
	   myCstring = new char[myCapacity];
    }
    myLength = len;
    strcpy(myCstring,s);
    return *this;
}

const apstring& apstring::operator = (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 = 2;
        myCstring = new char[myCapacity];
    }
    myLength = 1;
    myCstring[0] = ch;  // make string one character long
    myCstring[1] = '\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 <= 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 <= k)
    {
        cerr << "index out of range: " << k << " string: " << myCstring
            << endl;
        exit(1);
    }
    return myCstring[k];
}


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

    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 ch;
    str = "";    // empty string, will build one char at-a-time
    is >> ch;    // whitespace skipped, first non-white char in ch


    if (! is.fail())
    {
        do
        {
            str += ch;
            is.get(ch);
        } while (! is.fail() && ! isspace(ch));
  
        if (isspace(ch))    // put whitespace back on the stream
        {
            is.putback(ch);     
        }
    }
 
    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 ch;
    str = "";     // empty string, will build one char at-a-time
  
    while (is.get(ch) && ch != '\n')
    {
        str += ch;
    }
 
    return is;
}

const apstring& apstring::operator +=(const apstring & str)
//postcondition: concatenates a copy of str onto this string
{
    apstring copystring(str);         // copy to avoid aliasing problems

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

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

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

    return *this;
}

const apstring & apstring::operator += ( char ch )
// postcondition: concatenates a copy of ch onto this string
{
    apstring temp;   // make string equivalent of ch
    temp = ch;
    *this += 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 += 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 = ch;
    result += str;
    return result;
}

apstring operator + ( const apstring & str, char ch )
// postcondition: returns concatenation of str with ch
{
    apstring result(str);
    result += 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 <= pos <= 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 = 0;
    }

    if (pos >= myLength) return "";     // empty string
    int lastIndex = pos + len - 1;      // last char's index (to copy)
    
	if (lastIndex >= myLength)          // off end of string?
    {
        lastIndex = myLength-1;
    }
    apstring result(*this);               // make sure enough space allocated
    int j,k;
    for(j=0,k=pos; k <= lastIndex; j++,k++)
    {
        result.myCstring[j] = myCstring[k];
    }
    result.myCstring[j] = '\0';         // properly terminate C-string
    result.myLength = 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 == ck0, s1 == ck1, ..., s(m-1) == ck(m-1) and
//               there is no j < k0 such that s0 = cj, ...., sm == c(j+m-1),
//               then returns k0;
//               otherwise returns npos
{
    int len = str.length();
    int lastIndex = length() - len;
    int k;
    for(k=0; k <= lastIndex; k++)
    {
        if (strncmp(myCstring + k,str.c_str(),len) == 0) return k;
    }
    return npos;
}

int apstring::find( char ch ) const
// description:   finds the first occurrence of the character ch within this
//                string an
#ifndef _APSTRING_H
#define _APSTRING_H

#include <iostream>
using namespace std;
// uncomment line below if bool not built-in type
// #include "bool.h"

// *******************************************************************
//  Last Revised: 4/04/06 - corrected specification comments, dhj
//
//  4/04/06 corrected comments, dhj
//  4/04/06 - commented out the #include "bool.h", dhj
//
//  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 = ( const apstring & str ); // assign str
    const apstring & operator = ( const char * s );       // assign s
    const apstring & operator = ( 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 += ( const apstring & str );// append str
    const apstring & operator += ( 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 == ( const apstring & lhs, const apstring & rhs );
bool operator != ( const apstring & lhs, const apstring & rhs );
bool operator <  ( const apstring & lhs, const apstring & rhs );
bool operator <= ( const apstring & lhs, const apstring & rhs );
bool operator >  ( const apstring & lhs, const apstring & rhs );
bool operator >= ( 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 exit.
//
// The apstring class assumes that '\0' is not a valid
// character in an apstring. Any attempts to place '\0'
// in an apstring will result in undefined behavior. Generally
// this means that characters that follow the '\0' will not
// be considered part of the apstring for purposes of
// comparison, output, and subsequent copying.
//
// 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 = ( const string & rhs )
//    postcondition: normal assignment via copying has been performed
//
// string & operator = ( 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 = ( 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 == ck0, s1 == ck1, ..., s(m-1) == ck(m-1) and
//                   there is no j < k0 such that s0 = cj, ...., sm == 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 == ck, and there is no j < k such that ch == 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 <= pos <= 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 <= k < length()
//    postcondition: returns copy of the kth character
//
// char & operator [ ]( int k )
//    precondition:  0 <= k < length()
//    postcondition: returns reference to the kth character
//    note:          if this reference is used to write a '\0'
//                   subsequent results are undefined
//
// modifiers
//
// const string & operator += ( const string & str )
//    postcondition: concatenates a copy of str onto this string
//
// const string & operator += ( 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
//
//***************************************************************
#endif
// Jonathan Hooker
// Data Structures
// 1-23-07

#include <iostream>
#include <iomanip>
#include <math.h>
#include "apstring.h"
#include "logbook.h"

int DaysInMonth ( int, int );
void headingOutput(int);
void dates (int&, int, int);


Logbook::Logbook (int month, int year)
{
	int i;
	
	for (i=0; i < DaysInMonth ( logMonth, logYear ); i++)
		entries[i] = 0;
	logMonth = month;
	logYear = year;

}

void Logbook::putEntry ( int day, int value )
{
	entries[day - 1] = value;
	return;
}

int Logbook::getEntry ( int day ) const
{
	return entries[day - 1];
}

int Logbook::getMonth () const
{
	return logMonth;
}

int Logbook::getYear () const
{
	return logYear;
}

int Logbook::getDaysInMonth () const
{
	return DaysInMonth ( logMonth , logYear );
}

void Logbook::displayCalendar() const
{
	int year = logYear;				// Holds the year input.
	int startDay;					// Holds the start day of the year.
	int yearWidth;					// Determines the width of the year heading.
	int yearField;					// Determines the amount of spaces output before the year.
	int month = logMonth;			// Determines the month being output.
	int totalDays = 0;				// Holds the amount of days in the year.
	char exitYN = 'Y';				// Determines whether or not to exit the program.
	
	// Calculate the spaces before the year heading that is output.
	yearWidth = int((log(logYear)/log(10)) + .5);
	yearField = ((56 - yearWidth) / 2) + yearWidth;
	
	// Output the year heading.
	if (year < 0)
		cout << " " << setw (yearField) << abs(logYear) << " B.C." << endl;
	else
		cout << " " << setw (yearField) << logYear << " A.D." << endl;

	// Output the calendar.

	headingOutput(logMonth);
	totalDays = DaysInMonth (logMonth, logYear);

	startDay = StartDayOfMonth(logMonth, logYear)
	dates (startDay, totalDays, entries);

	return;
}

int StartDayOfMonth ( int logMonth, int logYear ) const
{
	int nYears, nLeapYears, nDaysToMonth = 0, i = 1;
	
	nYears = logYear - 1901;
	nLeapYears = nYears / 4;
	while (i > logMonth)
	{
		nDaysToMonth += DaysInMonth(i,logYear);
	}

	return ( 1 + nYears + nLeapYears + nDaysToMonth + day) % 7;
}

int DaysInMonth( int logMonth, int logYear )
{
	int totalDays;
	
	if ( logMonth == 9 || logMonth == 4 || logMonth == 6 || logMonth == 11 )
		totalDays = 30;
	else if ( logMonth == 2 && ( logYear % 4 == 0 && logYear % 100 != 0 ) || logYear % 400 == 0 )
		totalDays = 29;
	else if ( logMonth == 2 )
		totalDays = 28;
	else
		totalDays = 31;

	return totalDays;
}

void headingOutput(int month)
{

	const apstring jan = "January";			// Holds the string "January".
	const apstring feb = "February";		// Holds the string "February".
	const apstring mar = "March";			// Holds the string "March".
	const apstring apr = "April";			// Holds the string "April".
	const apstring may = "May";				// Holds the string "May".
	const apstring jun = "June";			// Holds the string "June".
	const apstring jul = "July";			// Holds the string "July".
	const apstring aug = "August";			// Holds the string "August".
	const apstring sep = "September";		// Holds the string "September".
	const apstring october = "October";		// Holds the string "October".
	const apstring nov = "November";		// Holds the string "November".
	const apstring december = "December";	// Holds the string "December".
	const char sun = 'S';					// Holds the character 'S'.
	const char mon = 'M';					// Holds the character 'M'.
	const char tue = 'T';					// Holds the character 'T'.
	const char wed = 'W';					// Holds the character 'W'.
	const char thu = 'T';					// Holds the character 'T'.
	const char fri = 'F';					// Holds the character 'F'.
	const char sat = 'S';					// Holds the character 'S'.
	
	apstring monthName;						// Holds the name of the month being output.
	int monthWidth;							// Determines the set width that is output before the month header.

	// Determine month name.
	if (month == 1)
		monthName = jan;
	else if (month == 2)
		monthName = feb;
	else if (month == 3)
		monthName = mar;
	else if (month == 4)
		monthName = apr;
	else if (month == 5)
		monthName = may;
	else if (month == 6)
		monthName = jun;
	else if (month == 7)
		monthName = jul;
	else if (month == 8)
		monthName = aug;
	else if (month == 9)
		monthName = sep;
	else if (month == 10)
		monthName = october;
	else if (month == 11)
		monthName = nov;
	else if (month == 12)
		monthName = december;

	// Determine spaces before month name.
	monthWidth = ((56 - monthName.length ()) /2) + monthName.length ();

	// Output the header for the month.
	cout << endl << endl << setw (monthWidth) << monthName << endl;
	cout << "  " << sun << "    " << mon << "    " << tue << "    " << wed << "    " << thu 
		 << "    " << fri << "    " << sat << " " << endl;
	cout << setw (56) << "________________________________________________________" 
		 << endl << endl;
	
	return;
}

void dates (int& startDay, int totalDays, int entries[])
{
	int countDays = 1;						// Determines what day is being output.
	int countSpaces = 0;					// Determines the amount of spaces output before the first day of the month.
	int countDaysOfWeek = startDay;			// Determines how many days have been output.

	// Output amount of spaces to go before the first day of the month.
	while (countSpaces < countDaysOfWeek)
	{
		cout << "   ";
		countSpaces++;
	}

	// Output the days in the month.
	while (countDays <= totalDays)
	{
		cout << setw(8) << countDays << ' ' << entries[countDays];
		countDays++;
		
		// Determine when to end the line.
		if (countDaysOfWeek >= 6)
		{
			countDaysOfWeek = 0;
			cout << endl;
		}
		else
			countDaysOfWeek++;
	}
	startDay = countDaysOfWeek;
}
//--------------------------------------------------------------------
//
//  Laboratory 1                                           logbook.h
//
//  Class declaration for the Logbook ADT
//
//--------------------------------------------------------------------

//using namespace std;

class Logbook
{
  public:

    // Constructor
	Logbook ( int month, int year );         // Create a logbook

    // Logbook marking operations
    void putEntry ( int day, int value );   // Store entry for day
    int getEntry ( int day ) const;         // Return entry for day

    // General operations
    int getMonth () const;                  // Return the month
    int getYear () const;                   // Return the year
    int getDaysInMonth () const;            // Number of days in month

    // In-lab operations
    void displayCalendar () const;          // Display as calendar
    //Logbook ();                             // Default constructor
    //void putEntry ( int value );            // Store entry for today
    //int operator [] ( int day ) const;      // Return entry for day
    //void operator += ( const Logbook &rightLogbook );
                                            // Combine logbooks
  private:

    // Facilitator (helper) function
    //bool isLeapYear () const;               // Leap year?

    // In-lab facilitator function
    int getDayOfWeek ( int day ) const;     // Return day of the week

    // Data members
    int logMonth,      // Month covered by logbook
        logYear,       // Year for this logbook
        entries[31];   // Logbook entries
};
//--------------------------------------------------------------------
//
//  Laboratory 1                                           test1.cpp
//
//  Test program for the operations in the Logbook ADT
//
//--------------------------------------------------------------------

#include <iostream>
#include "logbook.h"

using namespace std;

void main()
{
    int month,   // Input month
        year,    // Input year
        day,     // Input day
        entry,   // Input logbook entry
        dofw,    // Day of the week
        stop,    // Signals end of test
        j;       // Loop counter

    // Create a logbook (not used in Test 4).

    cout << endl << endl
         << "Enter the month and year for the logbook month : ";
    cin >> month >> year;
    Logbook testLog(month,year);

    // Test 1 : Tests the month, year, and daysInMonth operations.

    cout << "Month : " << testLog.getMonth() << endl;
    cout << "Year  : " << testLog.getYear() << endl;
    cout << "# days in month : " << testLog.getDaysInMonth() << endl;

   // // Test 2 : Tests the putEntry and getEntry operations.

   stop = 0;
   while ( !stop )
   {
      cout << endl << "Enter day and entry (0 0 to exit Test 2) : ";
       cin >> day >> entry;
       if ( day == 0  &&  entry == 0 )
         stop = 1;
       else
       {
          testLog.putEntry(day,entry);
          cout << "Logbook:" << endl;
          for ( day = 1 ; day <= testLog.getDaysInMonth() ; day++ )
          {
              cout << day << " " << testLog.getEntry(day) << '\t';
              if ( day % 5 == 0 )
                 cout << endl;
          }
          cout << endl;
       }
   }

// Test 3 : Tests the calendar operation.

  cout << endl;
  testLog.displayCalendar();
  cout << endl;

//4  // Test 4 : Tests the overloaded constructor and putEntry
//4  //          operations.
//4
//4  Logbook thisMonth;
//4  cout << endl << "Logbook for this month:" << endl;
//4  cout << "Month : " << thisMonth.getMonth() << endl;
//4  cout << "Year  : " << thisMonth.getYear() << endl;
//4  cout << "# days in month : " << thisMonth.getDaysInMonth() << endl;
//4  thisMonth.putEntry(100);
//4  for ( day = 1 ; day <= thisMonth.getDaysInMonth() ; day++ )
//4  {
//4      cout << day << " " << thisMonth.getEntry(day) << '\t';
//4      if ( day % 5 == 0 )
//4         cout << endl;
//4  }
//4  cout << endl;

//5  // Test 5 : Tests the [] operation.
//5
//5  cout << "Logbook:" << endl;
//5  for ( day = 1 ; day <= testLog.getDaysInMonth() ; day++ )
//5  {
//5      cout << day << " " << testLog[day] << '\t';
//5      if ( day % 5 == 0 )
//5         cout << endl;
//5  }
//5  cout << endl;

//6  // Test 6 : Tests the += operation.
//6
//6  Logbook logDay100(month,year),
//6          logDay200(month,year);
//6
//6  cout << endl
//6       << "Loading logbooks logDay100 and logDay200" << endl;
//6  for ( day = 1 ; day <= logDay100.getDaysInMonth() ; day++ )
//6  {
//6      logDay100.putEntry(day,100*day);
//6      logDay200.putEntry(day,200*day);
//6  }
//6
//6  logDay100 += logDay200;
//6
//6  cout << "Combined logbooks:" << endl;
//6  for ( day = 1 ; day <= logDay100.getDaysInMonth() ; day++ )
//6  {
//6      cout << day << " " << logDay100.getEntry(day) << '\t';
//6      if ( day % 5 == 0 )
//6         cout << endl;
//6  }
//6  cout << endl;

}

Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int apstring.h 70

Error 2 error C2556: 'std::ostream &operator <<(std::ostream &,const apstring &)' : overloaded function differs only by return type from 'int &operator <<(std::ostream &,const apstring &)' apstring.cpp 166

Error 3 error C2371: 'operator <<' : redefinition; different basic types c:\documents and settings\hooker\desktop\logbook\apstring.cpp 166

apstring.h has this typoed line in it.

ostream ;& operator << ( ostream & os, const apstring & str );

There's a rogue semicolon in there that shouldn't be.

ostream & operator << ( ostream & os, const apstring & str );

That should fix your errors. :)

It worked. Thanks.

Yes! Every once in a long while I guess right. I may even get a reputation for knowing what I'm talking about soon. ;)

This question has already been answered. Start a new discussion instead.