Thread: namespace std

  1. #16
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    If you want MFC you will have to get a compiler from microsoft.
    STL Util a small headers-only library with various utility functions. Mainly for fun but feedback is welcome.

  2. #17
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    Aren't MFCs VERY good for programming? Or is it better if I do it myself and learn the functions of it?

  3. #18
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    That is not something I know, I havent messed much with Win32 API nor with MFC.
    STL Util a small headers-only library with various utility functions. Mainly for fun but feedback is welcome.

  4. #19
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main (int argc, char *argv[])
    {
      cout << "Hello World!" << endl;
      cout << "Press ENTER to continue..." << endl; 
      cin.get();
      return 0;
    }
    Jesus no wonder I was so confused. Is this standard notation? What's with the " (int argc, char *argv[])"?

  5. #20
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    yah, its standard. that argc and argv is used for commandline parameters, check the faq or search for more info.
    STL Util a small headers-only library with various utility functions. Mainly for fun but feedback is welcome.

  6. #21
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    I liked it better the other way lol. It was way easier.

  7. #22
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    The "(int argc, char *argv[])" is for receiving arguments from the command line. So if you execute your program like this
    Code:
    C:\>program
    Those variables are
    Code:
    argc: 1
    argv: "program"
          NULL
    Whereas if you execute your program like this
    Code:
    C:\>program arg1 arg2 hippo
    The variables are
    Code:
    argc: 4
    argv: "program"
          "arg1"
          "arg2"
          "hippo"
          NULL
    It's useful for options and stuff.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #23
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    There is no need for the parameters to main if you do not make use of them. Both of the following are standard (and nothing else is):
    Code:
    int main( ) { ... }
    int main(int argc, char* argv[]) { ... }
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  9. #24
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    I'm wondering why use that code if you can do this:

    Code:
    #include <iostream>
    using namespace std
    
    int main() {
             cout << "This is much easier and produces the same results" << endl;
    }

  10. #25
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    <iostream.h> was never part of the C++ standard. It is not deprecated. It doesn't even work at all on modern compilers (including Microsoft's most recent versions). It works on VC++ 6 because that version was created at the same time as the standard and because legacy code from before the standard had to be supported. The standard header (<iostream>) works on VC++ 6 also, so there is no reason to use the old, non-standard header.

    The two forms of main specified by Zach L. are standard. There can be other forms, but they all must specify int as the return value. Again, VC++ 6 is just one compiler that happens to allow void main. Other more standards compliant compilers will not allow it. Why not use the one that works almost anywhere.

    Even though main must specify int as its return value, there is a special case for the main function that says that if you don't return a value, then 0 will be returned automatically. VC++ 6 gives a warning if you don't return something, but modern compilers allow
    Code:
    int main() { }
    as a legal program.

    VC++ is a good IDE, but I believe Dev-C++ and the Beta VC++ 2005 are both free and one of them is probably better given that they use much more standards-compliant compilers. If you have money, there are several compilers, including VC++ 7.1 (2003) that are better than version 6.

    The namespace was introduced to avoid naming conflicts. For small beginner programs the using namespace std; is fine. However, that basically nullifies the entire reason behind the feature that was created for the language. Read up on namespaces to find out why they are useful, and then decide if you want to take advantage of their benefits or if using the easy way is enough for you.
    Last edited by Daved; 07-23-2005 at 09:11 PM.

  11. #26
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    Okay just a checkup. It allows for two variables to have the same name. Example:

    Code:
    namespace int foo 
    int foo //another variable, same name
    Have I got it right? Maybe?

  12. #27
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Yes, that's the idea, although that isn't C++ syntax.
    Code:
    #include <iostream>
    #include <string>
    
    namespace foo { const int count = 100; }
    namespace bar { const std::string count = "Dracula"; }
    
    int main() { std::cout << foo::count << " " << bar::count << std::endl; }

  13. #28
    Registered User
    Join Date
    Jul 2005
    Posts
    1
    My first post on this forum, and it wasnt even a question lol. Thanks you answered my question before i could answer it.

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why std:: and not using namespace std?
    By swappo in forum C++ Programming
    Replies: 4
    Last Post: 07-03-2009, 03:10 PM
  2. std:: or namespace std
    By C-+ in forum C++ Programming
    Replies: 16
    Last Post: 12-04-2007, 12:30 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. need ; before using namespace std
    By wwfarch in forum C++ Programming
    Replies: 7
    Last Post: 05-11-2004, 10:42 PM
  5. Site tutorials
    By Aalmaron in forum C++ Programming
    Replies: 20
    Last Post: 01-06-2004, 02:38 PM