code does not compile

This is a discussion on code does not compile within the C++ Programming forums, part of the General Programming Boards category; i am using devc++ and my code is Code: #include<iostream> using namespace std; class complex { private : int a; ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    30

    code does not compile

    i am using devc++
    and my code is

    Code:
    #include<iostream>
    
    using namespace std;
    
    class complex
    {
        private :
            int a;
            int b;
        public :
            complexnum()
            {
                a = 0;
                b = 0;
            }
            void input()
            {
                cin >> a >> b;
            }
            void display()
            {
                cout << a << " + " << b <<"i";
            }
            void add(complexnum x,complexnum y);
            void sub(complexnum x,complexnum y);
    }    
    
    //implementation
    
    void complexnum :: add(complexnum x,complexnum y)
    {
        a = x.a + y.a;
        b = x.b + y.b;
    }
    void complexnum :: sub(complexnum x,complexnum y)
    {
        a = x.a - y.a;
        b = x.b - y.b;
    }
    
    //application
    
    int main()
    {
        complexnum c1,c2,c3;
    
        c1.input();
        c2.input();
    
        c3.add(c1,c2);
        c3.display();
    
        c3.sub(c1,c2);
        c3.display();
    }
    The errors encountered are.
    Compiler: Default compiler
    Executing gcc.exe...
    gcc.exe "C:\C++_Programming\complex.c" -o
    :1:19: iostream: No such file or directory
    :3: error: parse error before "namespace"
    :3: warning: data definition has no type or storage class
    :5: error: parse error before "complex"
    .........

    why is it so?
    please help......
    Last edited by aldajlo; 10-13-2004 at 03:26 AM. Reason: changing signature

  2. #2
    Bob Dole for '08 B0bDole's Avatar
    Join Date
    Sep 2004
    Posts
    618
    #include<iostream>
    thats your problem
    Hmm

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    30
    yes i know...........
    but it has to be there........
    so what is it thats wrong it that..........
    i am not getting it......
    please help me understand........

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    Also name your class one thing. Now it is both complex and complexnum.

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    30
    oh sorry.....
    but the problem starts with the first line itself.....
    how do i continue........knowing about others?
    please help me with that error it gives to me on the first line :
    "iostream : no such file or directory"

    please help me .......so that i can proceed.........
    being stuck here is getting me irritated.......
    i can't get anywhere......

    please help me.......
    Last edited by aldajlo; 10-13-2004 at 04:10 AM.
    Syra
    Amateur's urge to master C/C++

  6. #6
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712
    Code:
    #include<iostream>
    
    using namespace std;
    
    class complex
    {
        private :
            int a;
            int b;
        public :
            complexnum()
            {
                a = 0;
                b = 0;
            }
            void input()
            {
                cin >> a >> b;
            }
            void display()
            {
                cout << a << " + " << b <<"i";
            }
            void add(complexnum x,complexnum y);
            void sub(complexnum x,complexnum y);
    } ;// you forgot ;
    I personally would not implement this class methods the way you want, but...
    Last edited by Micko; 10-13-2004 at 04:19 AM.

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    Also try to reinstall dev and make sure you install it to the default directory (I think its something like C:\Dev-C++)

  8. #8
    Registered User
    Join Date
    Oct 2004
    Posts
    30

    Angry

    Code:
    #include <iostream>
    
    using namespace std;
    
    class complexnum
    all my question revolves around the first line ..............
    please answer my question ...............
    which is quite to the point........................

    1....in the first line............
    ......the error reported is
    ......"IOSTREAM - NO SUCH FILE OR DIRECTORY......"

    2....on the third line.............
    ......the error reported is
    ......"parse error before "namespace"

    I need to know this before anything else...............
    u need not tell me anything else before u answer my question .........
    i am not asking u to implement it either.........

    please i want the answer to MY question.....
    Syra
    Amateur's urge to master C/C++

  9. #9
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    Ok here is an answer: Your compiler is probably not set up correctly/not installed correctly. Uninstall and install again in default directory to see if that helps.

    Now, please answer my question a few posts down

  10. #10
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154
    the header file might be:

    Code:
    #include <iostream.h>
    just a thought...

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Bad thought. <iostream.h> is deprecated. Shakti is probably right: something in the compiler config is messed up.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  12. #12
    Registered User
    Join Date
    Oct 2004
    Posts
    30
    Thanks a lot ........

    Shakti you were right........
    i uninstalled Dev-C++ and then downloaded it again.....
    reinstalled it.......
    the program works fine.......

    thanks to all those who helped......
    Syra
    Amateur's urge to master C/C++

  13. #13
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Quote Originally Posted by CornedBee
    Bad thought. <iostream.h> is deprecated.
    I thought <iostream.h> wasn't standard.

  14. #14
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712
    Quote Originally Posted by jlou
    I thought <iostream.h> wasn't standard.
    That was in the old days. Now standard makes that issue very clear:

    "27.3 - Standard iostream objects [lib.iostream.objects]
    Header <iostream> synopsis

    namespace std {
    extern istream cin;
    extern ostream cout;
    extern ostream cerr;
    extern ostream clog;

    extern wistream wcin;
    extern wostream wcout;
    extern wostream wcerr;
    extern wostream wclog;
    }

    -1- The header <iostream> declares objects that associate objects with the standard C streams provided for by the functions declared in <cstdio> (lib.c.files).

    -2- Mixing operations on corresponding wide- and narrow-character streams follows the same semantics as mixing such operations on FILEs, as specified in Amendment 1 of the ISO C standard. The objects are constructed, and the associations are established at some time prior to or during first time an object of class basic_ios<charT,traits>::Init is constructed, and in any case before the body of main begins execution.*

    [Footnote: If it is possible for them to do so, implementations are encouraged to initialize the objects earlier than required. --- end foonote]
    The objects are not destroyed during program execution.*
    [Footnote: Constructors and destructors for static objects can access these objects to read input from stdin or write output to stdout or stderr. --- end foonote]
    "
    Cheers!

  15. #15
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Quote Originally Posted by Micko
    Quote Originally Posted by jlou
    I thought <iostream.h> wasn't standard.
    That was in the old days. Now standard makes that issue very clear.
    Thanks, but I think you missed my point.

    <iostream.h> was not standard in the old days, but it is now?


    I was pointing out that by saying that something is deprecated, you are saying it is standard, since deprecated generally means standard but no longer preferred. If I am not mistaken, <iostream.h> is not even mentioned in the standard, and so therefore it is completely non-standard.

    Since many of us try to recommend standards conformant code, it is a stronger statement to say that <iostream.h> is non-standard than to say it is deprecated.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code won't compile
    By monkles in forum C Programming
    Replies: 3
    Last Post: 05-28-2009, 01:45 PM
  2. Compile Errors in my Code. Can anyone help?
    By DGLaurynP in forum C Programming
    Replies: 1
    Last Post: 10-06-2008, 09:36 AM
  3. This code won't compile in Red Hat Linux 9
    By array in forum Linux Programming
    Replies: 7
    Last Post: 04-27-2004, 06:30 AM
  4. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Linux Programming
    Replies: 0
    Last Post: 10-14-2002, 01:30 PM
  5. How do they compile code for an OS ?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 49
    Last Post: 03-27-2002, 11:16 PM

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