CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2008
    Posts
    47

    using namespace std; declaration syntax error

    I am using Turbo C++ version 3.0, see the following code,
    when compiled, causes declaration syntax error


    #include<iostream.h>
    #include<conio.h>
    #include<fstream.h>
    using namespace std;
    int main()
    {
    //using namespace std;
    ofstream f;
    clrscr();
    f.open ("ittuz.txt");
    cout<<"Created";
    f<<"This is a file generated by c++ pgm \n ";
    f<<"by /n /t Ajmal thagha Muhammed";
    cout<<"Wrted to file";
    f.close();
    cout<<"closed";
    getch();
    return 0;
    }

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: using namespace std; declaration syntax error

    Quote Originally Posted by junaidsherief View Post
    I am using Turbo C++ version 3.0, see the following code,
    The reason for your error is that you are using an old, outdated, obsolete compiler. It is totally useless if you want to learn C++ as it stands today in the year 2010.

    C++ was standardized in 1998. That compiler goes back to 1992! You can't get anywhere using that dinosaur.

    There are many free, modern ANSI C++ compilers available. Visual Studio Express, gcc/mingw, etc. Please get one of these compilers, and then start over.

    As to your code, the correct headers are <iostream> and <fstream>, not <iostream.h> and <fstream.h>.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Oct 2010
    Posts
    1

    Re: using namespace std; declaration syntax error

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

    are technically correct but are old code from C, use it without the .h

  4. #4
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: using namespace std; declaration syntax error

    Quote Originally Posted by tyranthacker View Post
    #include<iostream.h>
    #include<conio.h>
    #include<fstream.h>

    are technically correct but are old code from C, use it without the .h
    Except for conio, those are neither "technically correct", nor from C.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  5. #5
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: using namespace std; declaration syntax error

    When were namespaces introduced to C++ anyway?
    My hobby projects:
    www.rclsoftware.org.uk

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: using namespace std; declaration syntax error

    Quote Originally Posted by Zaccheus View Post
    When were namespaces introduced to C++ anyway?
    I believe they were in the original ARM (Annotated Reference Manual) before standardization in 1998, but no compiler was forced to implement them until 1998.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Jan 2008
    Posts
    47

    Re: using namespace std; declaration syntax error

    Thanks to all, solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured