Solved

overloading the << operator?

Posted on 2002-03-24
36
315 Views
Last Modified: 2010-04-02
Hi,

I am relatively new to overloading, but I am developing a hw for class and i got stuck on something.  so i got bored and started to mess around with me main program a bit.  anyways to make a long story short,
current i got this:

cout << "\nResults: ";
ts1.display();
cout << "\nResults: ";
ts2.display();
....etc...

i rather do this cout << "\nresults: " << ts1.display();

so would that mean i need to overload the << ?
or another way?

thnx

jw
0
Comment
Question by:weinrj
  • 17
  • 9
  • 5
  • +3
36 Comments
 
LVL 1

Expert Comment

by:lidorc
ID: 6892799
Yes, you can overload the << operator in the ts1 class and then write ..<< ts1 << .. read about it in the msdn, it's very simple to implement..
0
 
LVL 2

Accepted Solution

by:
LoungeLizard earned 25 total points
ID: 6892838
Well, it depends on what ts1.display() returns. If it is one of the "standard" types (int, char, char * etc. - easy enough to check, just compile and see if you get errors) then you do NOT need to overload << for cout because that was already done for you.

If, however, ts1.display() returns a custom class then you'll need to provide a implimentation of operator<< for cout that takes care of your specific class, something like: (look at the correct header file for details of cout's implementation - this is just a guess)

cout const & operator<<(myClass const & obj)
{
  // Your code here
}

0
 

Author Comment

by:weinrj
ID: 6892840
well does the operator << take any paramters?
i am a bit confused on the matter.
0
 

Author Comment

by:weinrj
ID: 6892847
here is the header file.
i tried doing cout << ts1.display(); and i got about 2 pages worth of compilation errors!

class TimeStamp {
   private:
      int year;
      int month;
      int day;
      int hour;
      int minute;
   public:
      TimeStamp() {};
      TimeStamp( int yr, int mo, int da, int ho, int mi );
      void display();
      bool operator >( TimeStamp &rhs );
      void diff( TimeStamp &ts2, int &weeks, int &days, int &hours, int &minutes );
      static const int daysInMonth[ 13 ];
   private:
      int dayofyear();
};

0
 
LVL 1

Expert Comment

by:lidorc
ID: 6892852
Don't do: cout << ts1.display();
but do:   cout << ts1;

And implement the operator << in the class TimeStamp:

class TimeStamp
{
    ...
    ...
    ostream & operator<<(ostream & os)
    {
        os << i << j << k; //where i,j,k are the data to print..
    }
    ...
}


After you implement the << operator you don't need the display method function any more..
0
 
LVL 2

Expert Comment

by:LoungeLizard
ID: 6892857
Well, it depends on what ts1.display() returns. If it is one of the "standard" types (int, char, char
* etc. - easy enough to check, just compile and see if you get errors) then you do NOT need to overload
<< for cout because that was already done for you.

If, however, ts1.display() returns a custom class then you'll need to provide a implimentation of operator<<
for cout that takes care of your specific class, something like: (look at the correct header file for
details of cout's implementation - this is just a guess)

cout const & cout::operator<<(myClass const & obj)
{
 // Your code here
}

If ts1.display() doesn't return anything but just prints a bunch of stuff (as it looks like in this case) then you will not be able to do what you want to do here. Remember that the operator<< is just a function like any other and needs a variable of some kind to work with.
0
 

Author Comment

by:weinrj
ID: 6892860
oh...

right now the  << function does calls the display function itself, but i guess that idea didnt work yet...lemme play around a bit...

0
 

Author Comment

by:weinrj
ID: 6892864
exactly all diplay does is converts data and cout's one thing at the end.  thats it..believe it or not, the display function is quite long itself.  now the display function, i should then just rename it as the operator << one?

jw
0
 
LVL 1

Expert Comment

by:lidorc
ID: 6892869
Show me your display function.. It isn't only renaming it to <<, the implementation is different, but it simple..
0
 

Author Comment

by:weinrj
ID: 6892884
the display function is huge, but ok....( i am sure it can be simplified too but oh well... i am a student!)

void TimeStamp::display() {
   // display stuff.  as of now i dont know what!
   // i think displ Friday, March 8, 2002 at 2:05 PM
   // limiations, only for 1901 - 2099.
   // todo: add everything to the same string and output the one string.....
   // get full use of leapyear....
   int remainder = 0;
   int total     = ( year - 1900 ) * 5 / 4 + day;
   string tag;
   string monat;
   string ampm;
   string ender;

   switch ( month ) {
      case 1:
         total += 1;
         monat =   "Janurary ";
         break;
      case 2:
         total += 4;
         monat =  "February ";
         break;
      case 3:
         total += 4;
         monat =  "March ";
         break;
      case 4:
         total += 0;
         monat =   "April ";
         break;
      case 5:
         total += 2;
         monat =  "May ";
         break;
      case 6:
         total += 5;
         monat =   "June ";
         break;
      case 7:
         total += 0;
         monat =  "July ";
         break;
      case 8:
         total += 3;
         monat =  "August ";
         break;
      case 9:
         total += 6;
         monat =  "September ";
         break;
      case 10:
         total += 1;
         monat =  "October ";
         break;
      case 11:
         total += 4;
         monat =  "November ";
         break;
      case 12:
         total += 6;
         monat =  "December ";
         break;
   }

   if ( year % 4 == 0 && ( month == 1 || month == 2 ) )
      total -= 1;

   remainder = total % 7;

   switch(remainder) {
      case 0:
         tag =  "Saturday";
         break;
      case 1:
         tag =  "Sunday";
         break;
      case 2:
         tag =  "Monday";
         break;
      case 3:
         tag =  "Tuesday";
         break;
      case 4:
         tag =  "Wednesday";
         break;
      case 5:
         tag =  "Thursday";
         break;
      case 6:
         tag =  "Friday";
         break;
   }

//   cout << tag << monat << day << ", " << year << " at ";

   int tmpHr = hour;     // temp hr to convert non 24hr
   int lhs = 0;
   int rhs = 0;
   if ( hour > 12 )
      tmpHr -= 12;
   if ( hour == 0 )
      tmpHr = 12;



   if ( minute < 10 ){
  //    cout << "0" << minute;
        lhs = 0;
        rhs = minute;
   }

   else {
   //   cout << minute;
         lhs = minute / 10;
         rhs = minute % 10;
   }

   if ( hour >= 12 )
        ampm = " PM";
   else
        ampm = " AM";

   // adds neat ending

   if (day == 1 || day == 21 || day == 31)
        ender = "st";
   else if (day == 2 || day == 22)
        ender = "nd";
   else if (day == 3 || day == 23)
        ender = "rd";
   else
        ender = "th";

   // the full date!!!!
   cout << tag << ", " << monat << day << ender << ", " << year << " at " << tmpHr << ":" << lhs << rhs << ampm << ".";

}
0
 

Author Comment

by:weinrj
ID: 6892888
so pretty much it will output:

Tuesday, December 30th, 1980 at 9:39 PM.

0
 
LVL 2

Expert Comment

by:LoungeLizard
ID: 6892935
Sorry about the double post above. Anyway, for what you want to do, I think the following might be the easiest:

use

char const * TimeStamp::display()

and then at the end of your function use:


char buf[250]; // declare a buffer that will hold our printable data

strstream str(buf,250); // delcare a string stream into which data will be written, which uses buf as storage area

memset(buf,0,250); // clear the buffer

str << tag << ", " << monat << day << ender << ", " << year << " at " << tmpHr << ":" << lhs <<
rhs << ampm << ".";

return buf;

And then in main you simply use cout << ts1.display() as you wanted. What happens now is that you function returns a pointer to a char buffer and cout KNOWS how to handle that
0
 

Author Comment

by:weinrj
ID: 6892989
~/275 $ g++ -o time2 timestamp.cc timedriver.cc
timestamp.cc: In member function `const char* TimeStamp::display()':
timestamp.cc:162: `strstream' undeclared (first use this function)
timestamp.cc:162: (Each undeclared identifier is reported only once for each
   function it appears in.)
timestamp.cc:164: `str' undeclared (first use this function)
timestamp.cc:161: warning: address of local variable `buf' returned
0
 
LVL 2

Expert Comment

by:LoungeLizard
ID: 6893007
just #include <strstream>
0
 

Author Comment

by:weinrj
ID: 6893060
hmm duh!

but..
~/275 $ g++ -o time2 timestamp.cc timedriver.cc3C [w]
timestamp.cc: In member function `const char* TimeStamp::display()':
timestamp.cc:164: `str' undeclared (first use this function)
timestamp.cc:164: (Each undeclared identifier is reported only once for each
   function it appears in.)
timestamp.cc:161: warning: address of local variable `buf' returned
0
 
LVL 30

Expert Comment

by:Axter
ID: 6893102
According to the C++ standards, strstream is a deprecated class, and should not be used in any new code.

Use stringstream instead.
0
 
LVL 2

Expert Comment

by:LoungeLizard
ID: 6893121
True. However, a lot of compiler do not yet support stringstream, including g++ (it seems), which is used here

>>timestamp.cc:164: `str' undeclared (first use this function)


I din't see how this is possible if you have included

strstream str(buf,250);
0
 
LVL 30

Expert Comment

by:Axter
ID: 6893123
Try the following method:

#include <sstream>
std::string TimeStamp::display() {
  // display stuff.  as of now i dont know what!
  // i think displ Friday, March 8, 2002 at 2:05 PM
  // limiations, only for 1901 - 2099.
  // todo: add everything to the same string and output the one string.....
  // get full use of leapyear....
  int remainder = 0;
  int total     = ( year - 1900 ) * 5 / 4 + day;
  string tag;
  string monat;
  string ampm;
  string ender;

  switch ( month ) {
     case 1:
        total += 1;
        monat =   "Janurary ";
        break;
     case 2:
        total += 4;
        monat =  "February ";
        break;
     case 3:
        total += 4;
        monat =  "March ";
        break;
     case 4:
        total += 0;
        monat =   "April ";
        break;
     case 5:
        total += 2;
        monat =  "May ";
        break;
     case 6:
        total += 5;
        monat =   "June ";
        break;
     case 7:
        total += 0;
        monat =  "July ";
        break;
     case 8:
        total += 3;
        monat =  "August ";
        break;
     case 9:
        total += 6;
        monat =  "September ";
        break;
     case 10:
        total += 1;
        monat =  "October ";
        break;
     case 11:
        total += 4;
        monat =  "November ";
        break;
     case 12:
        total += 6;
        monat =  "December ";
        break;
  }

  if ( year % 4 == 0 && ( month == 1 || month == 2 ) )
     total -= 1;

  remainder = total % 7;

  switch(remainder) {
     case 0:
        tag =  "Saturday";
        break;
     case 1:
        tag =  "Sunday";
        break;
     case 2:
        tag =  "Monday";
        break;
     case 3:
        tag =  "Tuesday";
        break;
     case 4:
        tag =  "Wednesday";
        break;
     case 5:
        tag =  "Thursday";
        break;
     case 6:
        tag =  "Friday";
        break;
  }

//   cout << tag << monat << day << ", " << year << " at ";

  int tmpHr = hour;     // temp hr to convert non 24hr
  int lhs = 0;
  int rhs = 0;
  if ( hour > 12 )
     tmpHr -= 12;
  if ( hour == 0 )
     tmpHr = 12;



  if ( minute < 10 ){
 //    cout << "0" << minute;
       lhs = 0;
       rhs = minute;
  }

  else {
  //   cout << minute;
        lhs = minute / 10;
        rhs = minute % 10;
  }

  if ( hour >= 12 )
       ampm = " PM";
  else
       ampm = " AM";

  // adds neat ending

  if (day == 1 || day == 21 || day == 31)
       ender = "st";
  else if (day == 2 || day == 22)
       ender = "nd";
  else if (day == 3 || day == 23)
       ender = "rd";
  else
       ender = "th";

  // the full date!!!!
  std::ostringstream iss;
  iss << tag << ", " << monat << day << ender << ", " << year << " at " << tmpHr << ":" << lhs << rhs << ampm << ".";
  return iss.str();

}
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 30

Expert Comment

by:Axter
ID: 6893127
All I changed in your code was the return type and the last few lines.
Also don't forget to add the new include <sstream>

#include <sstream>
std::string TimeStamp::display() {

//.................
  //The rest of your code
//.................


// the full date!!!!
 std::ostringstream iss;
 iss << tag << ", " << monat << day << ender << ", " << year << " at " << tmpHr << ":" << lhs << rhs
<< ampm << ".";
 return iss.str();
}
0
 

Author Comment

by:weinrj
ID: 6893129
okay! i will look at it a bit later...i got another member function i am working on....
0
 
LVL 30

Expert Comment

by:Axter
ID: 6893131
Note:
If you're using an older version of the GNU compiler, using stringstream won't work, because the older version did not include implementation for stringstream.

Version 3.0 and higher does include support for stringstream.
0
 

Author Comment

by:weinrj
ID: 6893134
~/275 $ g++ --version
3.0.3
0
 

Author Comment

by:weinrj
ID: 6893137
lab machines use 2.x bc they were dumb and never installed new version yet...they are aware of the 3 which the server runs.....
0
 

Author Comment

by:weinrj
ID: 6893139
well what exactly is the protype supposed to be for the header file?
0
 
LVL 30

Expert Comment

by:Axter
ID: 6893143
LoungeLizard,
>>True. However, a lot of compiler do not yet support
>>stringstream, including g++ (it seems), which is
>>used here

Only the older version of the GNU (g++) compiler doesn't have support for stringstream.
The current 3.0.4 version does support stringstream.

If you have a compiler that does not support stringstream, you're better of replaceing the compiler, then to use deprecated code.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6893145
If you have to use the depricated class, then try the following code.

#include <strstream>
std::string TimeStamp::display() {

//.................
 //The rest of your code
//.................


  // the full date!!!!
  strstream iss;
  iss << tag << ", " << monat << day << ender << ", " << year << " at " << tmpHr << ":" << lhs << rhs << ampm << ".";
  return iss.str();
}
0
 

Author Comment

by:weinrj
ID: 6893147
3.0.3 does not support?

if not its okay...it looks more complicated than i origianly anticipated, as i thought just overloading the operator is all thats needed, thus my original question.  so i can try to do it this way later on but i got a few more things to do before midnight tuesday!  thanks fr all the help so far!
0
 

Author Comment

by:weinrj
ID: 6893151
3.0.3 does not support?

if not its okay...it looks more complicated than i origianly anticipated, as i thought just overloading the operator is all thats needed, thus my original question.  so i can try to do it this way later on but i got a few more things to do before midnight tuesday!  thanks fr all the help so far!
0
 
LVL 30

Expert Comment

by:Axter
ID: 6893156
3.0.3 does support stirngstream.

Correction on the last post for depricated strstream code.
Try this:

#include <strstream>
std::string TimeStamp::display() {

//.................
//The rest of your code
//.................


  // the full date!!!!
  strstream iss;
  iss << tag << ", " << monat << day << ender << ", " << year << " at " << tmpHr << ":" << lhs << rhs << ampm << ".";
  return std::string(iss.str(), iss.str()+iss.pcount());
}
0
 

Author Comment

by:weinrj
ID: 6893163
but what exactly do i put in the header file?
all i got now is void display()

since i am return somehting now i got very very confused...i dont even know what all this stuff does anyways...maybe i will after i get my degree, but certainly not now.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6893166
FYI:
I had to write some code that could compile on both the 2.7 version and the 3.0 > version of the GNU compiler.
So I made the following class, that would compile only in the older 2.7 version of the compiler.

#if defined(__GNUC__) && __GNUC__  < 3  && __GNUC_MINOR__ < 96
#include <strstream>
class StrngStream
{
public:
     StrngStream():m_stream(new std::ostrstream){}
     ~StrngStream(){delete m_stream;}
     StrngStream& operator<<(const char* Src)
     {
          *m_stream << Src;
          return *this;
     }
     StrngStream& operator<<(const std::string &Src)
     {
          *m_stream << Src.c_str();
          return *this;
     }
     std::string str() const
     {
          return std::string(m_stream->str(), m_stream->str()+m_stream->pcount());
     }
     void str(const char *Src)
     {
          if (Src)
          {
               delete m_stream;
               m_stream = new std::ostrstream;
          }
     }
private:
     std::ostrstream *m_stream;
};
#else //defined(__GNUC__) && __GNUC__  < 3  && __GNUC_MINOR__ < 96
#include <sstream>
typedef std::ostringstream StrngStream;
#endif //defined(__GNUC__) && __GNUC__  < 3  && __GNUC_MINOR__ < 96


I then used StrngStream in my code.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6893169
>>but what exactly do i put in the header file?
>>all i got now is void display()

Just change your header file to match the new type:

Change it to the following:
std::string display();

0
 

Author Comment

by:weinrj
ID: 6893181
i give up...my old way works just as well.

thnx

~/275 $ g++ -o time2a timestamp.v1.cc timedriver.v1.cc
timestamp.v1.cc:27: prototype for `std::string TimeStamp::display()' does not
   match any in class `TimeStamp'
timestamp.h:11: candidate is: void TimeStamp::display()
timedriver.v1.cc: In function `int main()':
timedriver.v1.cc:110: no match for `std::basic_ostream<char,
   std::char_traits<char> >& << void' operator
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:50: candidates are:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(std::basic_ostream<_CharT,
   _Traits>&(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char,
   _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:72:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(std::basic_ios<_CharT,
   _Traits>&(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits
   = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:94:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(std::ios_base&(*)(std::ios_base&)) [with _CharT = char,
   _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:140:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(long int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:177:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:115:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(bool) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:99:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(short int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:110:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:114:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:125:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:203:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(long long int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:241:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:267:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(double) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:140:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(float) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:292:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(long double) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:317:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(const void*) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:342:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT =
   char, _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:215:
   std::basic_ostream<_CharT, _Traits>&
   std::operator<<(std::basic_ostream<_CharT, _Traits>&, char) [with _CharT =
   char, _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:575:
   std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char,
   _Traits>&, char) [with _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:226:
   std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char,
   _Traits>&, signed char) [with _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:231:
   std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char,
   _Traits>&, unsigned char) [with _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:643:
   std::basic_ostream<_CharT, _Traits>&
   std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*) [with
   _CharT = char, _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:689:
   std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char,
   _Traits>&, const char*) [with _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:250:
   std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char,
   _Traits>&, const signed char*) [with _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:255:
   std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char,
   _Traits>&, const unsigned char*) [with _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_iomanip.h:67:
   std::basic_ostream<_CharT, _Traits>&
   std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Resetiosflags)
   [with _CharT = char, _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_iomanip.h:94:
   std::basic_ostream<_CharT, _Traits>&
   std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setiosflags)
   [with _CharT = char, _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_iomanip.h:124:
   std::basic_ostream<_CharT, _Traits>&
   std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setbase) [with
   _CharT = char, _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_iomanip.h:183:
   std::basic_ostream<_CharT, _Traits>&
   std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setprecision)
   [with _CharT = char, _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_iomanip.h:210:
   std::basic_ostream<_CharT, _Traits>&
   std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setw) [with
   _CharT = char, _Traits = std::char_traits<char>]
~/275 $
0
 

Author Comment

by:weinrj
ID: 6893189
i give up...my old way works just as well.

thnx

~/275 $ g++ -o time2a timestamp.v1.cc timedriver.v1.cc
timestamp.v1.cc:27: prototype for `std::string TimeStamp::display()' does not
   match any in class `TimeStamp'
timestamp.h:11: candidate is: void TimeStamp::display()
timedriver.v1.cc: In function `int main()':
timedriver.v1.cc:110: no match for `std::basic_ostream<char,
   std::char_traits<char> >& << void' operator
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:50: candidates are:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(std::basic_ostream<_CharT,
   _Traits>&(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char,
   _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:72:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(std::basic_ios<_CharT,
   _Traits>&(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits
   = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:94:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(std::ios_base&(*)(std::ios_base&)) [with _CharT = char,
   _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:140:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(long int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:177:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:115:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(bool) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:99:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(short int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:110:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:114:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:125:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:203:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(long long int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:241:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:267:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(double) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:140:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(float) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:292:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(long double) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:317:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(const void*) [with _CharT = char, _Traits =
   std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:342:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT =
   char, _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:215:
   std::basic_ostream<_CharT, _Traits>&
   std::operator<<(std::basic_ostream<_CharT, _Traits>&, char) [with _CharT =
   char, _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:575:
   std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char,
   _Traits>&, char) [with _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:226:
   std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char,
   _Traits>&, signed char) [with _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:231:
   std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char,
   _Traits>&, unsigned char) [with _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:643:
   std::basic_ostream<_CharT, _Traits>&
   std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*) [with
   _CharT = char, _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/ostream.tcc:689:
   std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char,
   _Traits>&, const char*) [with _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:250:
   std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char,
   _Traits>&, const signed char*) [with _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_ostream.h:255:
   std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char,
   _Traits>&, const unsigned char*) [with _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_iomanip.h:67:
   std::basic_ostream<_CharT, _Traits>&
   std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Resetiosflags)
   [with _CharT = char, _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_iomanip.h:94:
   std::basic_ostream<_CharT, _Traits>&
   std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setiosflags)
   [with _CharT = char, _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_iomanip.h:124:
   std::basic_ostream<_CharT, _Traits>&
   std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setbase) [with
   _CharT = char, _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_iomanip.h:183:
   std::basic_ostream<_CharT, _Traits>&
   std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setprecision)
   [with _CharT = char, _Traits = std::char_traits<char>]
/usr/local/gcc3/include/g++-v3/bits/std_iomanip.h:210:
   std::basic_ostream<_CharT, _Traits>&
   std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setw) [with
   _CharT = char, _Traits = std::char_traits<char>]
~/275 $
0
 
LVL 11

Expert Comment

by:griessh
ID: 6956091
Dear weinrj

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to split between

     "Axter & LoungeLizard"

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/

=========================================================
You have 13 open questions out of 90 that need your attention! Please take
some time and accept an answer if an expert was able to help you or
provide feedback if needed.
==========================================================

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 6979147
Force accepted

Axter, there will be a separate question with points for your help.

** Mindphaser - Community Support Moderator **
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now