Problems with istream

This is a discussion on Problems with istream within the C++ Programming forums, part of the General Programming Boards category; When I compile some old source code downloaded from Internet, I sometimes encounter the problems with #include <fstream.h> #include <iostream.h> ...

  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
    21,456
    You should qualify istream with std:: since it belongs to the std namespace.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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.
    Attached Images Attached Images  
    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,317
    Why is k an unsigned char? The error is saying that you can't call get() and pass an unsigned char.

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

    Code:
    #include <cstdio>
    #include <cstdlib>
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  7. #7
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    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...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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, 04: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, 03:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21