Thread: Problems with istream

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    11

    Problems with istream

    When I compile some old source code downloaded from Internet, I sometimes encounter the problems with

    #include <fstream.h>
    #include <iostream.h>

    The g++ compiler in cygwin claims the following errors:

    In file included from /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/backward/fstream.h:31,
    from decode.cpp:5:
    /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.

    in a class like that:
    Code:
    class e
    {
    public:
    	e(istream&f);
                    .....
    }
    I changed the header files as:

    #include <fstream>
    #include <iostream>


    But the g++ still says:

    decode.cpp:37: error: expected `)' before '&' token
    decode.cpp:55: error: ISO C++ forbids declaration of `istream' with no type

    What can I do to fix this problem? Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You should qualify istream with std:: since it belongs to the std namespace.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    11
    Thanks for replying. I tried add std:: , but I still get some other errors. The code is posted here. I thought the main problem is with the istream class.



    The compile error is shown as the figure. Any ideas are really appreciated.
    Last edited by igoogleu; 03-26-2008 at 09:16 PM.

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    11
    Sorry, the code is a little bit longer and the varibles are not well named because the author wants to make the code short.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Why is k an unsigned char? The error is saying that you can't call get() and pass an unsigned char.

  6. #6
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    #include <stdio.h>
    #include <stdlib.h>
    proper C++ includes are

    Code:
    #include <cstdio>
    #include <cstdlib>
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  7. #7
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    why math code should be in header? it is not template...
    what these divide by zero warnings? Is it intended?

    if(!j.eof()) - do not use eof to control loop - read FAQ


    j.get(k); - try to read as char and cast to unsigned char later...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  8. #8
    Registered User
    Join Date
    Mar 2008
    Posts
    11
    I followed Daved and vart's suggestions to modify the get() function. Then it is ok.
    This forum is really quickly-replied and informed. Thanks all replies.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. istream
    By Beowolf in forum C++ Programming
    Replies: 3
    Last Post: 10-30-2007, 05:11 PM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. problems with >> istream overloading
    By rip1968 in forum C++ Programming
    Replies: 4
    Last Post: 05-06-2002, 03:38 PM
  5. <list>
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 02-24-2002, 04:07 PM