Thread: namespace help

  1. #1
    Registered User
    Join Date
    Jan 2004

    namespace help

    while using namespace std, many of the fstream functions seem to not work. yet it is essential for my program to include ios::nocreate and file.is_open(), any suggestions?
    btw i cant not use namespace std cuz i need strings in my program and arrays of chars are too complicated if it were to be used as a substitute. any help would be appreciated
    Last edited by dodge_tomahawk; 01-03-2004 at 04:16 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    It seems to me that you're stuck between old and new C++, and whether you should/shouldn't use namespaces.

    Can you post some code to show us what you're trying to do?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    California, US
    ios :: nocreate is not standard C++. You should be using ios :: in. I posted about the nocreate thing awhile ago. Instead of using namespace std; it's better if you use only specific things:

    #include <iostream> //Most likely needed
    #include <fstream>   //For I/O stream
    #include <string> //For strings
    using std :: cout; // Almost in all programs
    using std :: ofstream; //Ofstream
    using std :: ifstream; //Ifstream
    using std :: string; //Strings
    using std :: ios; //Ios :: in
    Ofcourse it's better to use it at the same time you use the thing, for example:

    std :: ofstream a_file("example.txt", std :: ios :: in);
    Hope this helps.

    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. extern namespace?
    By Brafil in forum C++ Programming
    Replies: 2
    Last Post: 01-10-2009, 08:06 AM
  2. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. data validation & namespace
    By tiange in forum C++ Programming
    Replies: 4
    Last Post: 07-05-2005, 02:45 AM