namespace help

This is a discussion on namespace help within the C++ Programming forums, part of the General Programming Boards category; while using namespace std, many of the fstream functions seem to not work. yet it is essential for my program ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    1

    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
    Location
    The edge of the known universe
    Posts
    32,855
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    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:

    Code:
    #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:

    Code:
    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, 04: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, 09:39 AM
  5. data validation & namespace
    By tiange in forum C++ Programming
    Replies: 4
    Last Post: 07-05-2005, 03:45 AM

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