Topic: ARG! a != problem with '\n


Author: sailer@a4430edc.esr.hp.com (Lee Sailer)
Date: 2 Nov 1994 22:25:52 GMT
Raw View
In article <398gjt$jhs@news.mtu.edu>, Brian A. Bucher (babucher@mtu.edu) wrote:


> I have been having some major problem trying to figure this out.  I want
> to read in something from a file and check to see if it is an end-of-line
> character.

> // early in the program
> template<class T>
> //etc...

> // later...
> // declaring a pointer to type T where T is replaced by either int, float
> // or char
>  T *anItem;

> // getting something from a file
> anItem = inClientFile.get();

> // if what i read from the file is not an end-of-line character, then do
> // some stuff

> while(anItem != '\n')
> { do stuff}


> how do i make it so i can compare anItem with '\n'?
> thanks

There are probably lots of solutions.  One might be to overload
operator != () as a member function in the template.




Author: babucher@mtu.edu (Brian A. Bucher)
Date: 2 Nov 1994 17:00:45 GMT
Raw View

I have been having some major problem trying to figure this out.  I want
to read in something from a file and check to see if it is an end-of-line
character.

// early in the program
template<class T>
//etc...

// later...
// declaring a pointer to type T where T is replaced by either int, float
// or char
 T *anItem;

// getting something from a file
anItem = inClientFile.get();

// if what i read from the file is not an end-of-line character, then do
// some stuff

while(anItem != '\n')
{ do stuff}


how do i make it so i can compare anItem with '\n'?
thanks
--
-----------------------------------------------------------------
Brian Bucher - Computer Consultant, Division of Chemical Sciences




Author: schuenem@Informatik.TU-Muenchen.DE (Ulf Schuenemann)
Date: 4 Nov 1994 15:56:27 GMT
Raw View
In article <398gjt$jhs@news.mtu.edu>, babucher@mtu.edu (Brian A. Bucher) writes:
|> // early in the program
|> template<class T>
|> //etc...
|>
|> // later...
|> // declaring a pointer to type T where T is replaced by either int, float
|> // or char
|>  T *anItem;
|>
|> // getting something from a file
|> anItem = inClientFile.get();
|>
|> // if what i read from the file is not an end-of-line character, then do
|> // some stuff
|>
|> while(anItem != '\n')
|> { do stuff}
|>
|>
|> how do i make it so i can compare anItem with '\n'?

anItem is a _pointer_ to T. Comparing pointer to character is not
what you intended (hope so). Try " *anItem != '\n' "
it should work for all T that have an operator!=.

Or to allow writing "anItem != '\n'":

 template<class T>
 bool operator(const T*t, char c)
 {
 return *t == c;
 }

Ulf Schuenemann

--------------------------------------------------------------------
Ulf Sch   nemann
Institut f   r Informatik, Technische Universit   t M   nchen.
email: schuenem@informatik.tu-muenchen.de




Author: babucher@mtu.edu (Brian A. Bucher)
Date: 4 Nov 1994 19:14:04 GMT
Raw View
Thanks for all the help! I have that bug figured out...now on to the
next one. (joy)
--
-----------------------------------------------------------------
Brian Bucher - Computer Consultant, Division of Chemical Sciences