Thread: fstream - Console vs. Windows

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    9

    fstream - Console vs. Windows

    I'm writing a Windows program in VC++.NET and I want to use the fstream object. This worked fine as a console app.

    This is a Windows Form Application so I could take advantage of the Drag and drop functionality.

    I included the fstream file

    Code:
    #include <fstream>
    and I want to say

    Code:
    fstream reader;
    and it tells me that ''reader' is an undeclared identifier' and then tells me ''fstream' is an undeclared identifier!' What is wrong with it? Why does it work in a console app and not in a windows app? There are many more errors that I get, it seems many things that work just fine in a console app do not work in a Windows app. What's wrong?
    Last edited by tazz25; 12-31-2006 at 11:39 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Are you sure that it is not a namespace problem?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    9
    I don't know. In the console app I did this...
    Code:
    using namespace std;
    VC++.NET puts in a lot of other namespaces like System, System:: Data, System:: Drawing, etc...

    I don't really know how to work with namespaces I'm kind of new... It won't let me type
    Code:
    using namespace std;
    it says 'a namespace with this name does not exist'.
    Last edited by tazz25; 12-31-2006 at 11:41 AM.

  4. #4
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    i havent done any GUI programming for a couple years now...but as far as I know the std namespace should always exist...it is part of the heart and core of the C++ standard libraries.

    try declaring your fstream with std:: in front. example:

    Code:
    std::ifstream reader;
    My Website

    "Circular logic is good because it is."

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    9
    Code:
    std::ifstream reader;
    If I do that it gives me the same previous errors plus more errors, saying 'std is not a class or namespace name.'

    I know its not a problem like the std namespace is missing or something because it works fine in console programs.

    How's this line of code?

    Code:
    VisualStudios = annoying;
    Any other suggestions?
    Last edited by tazz25; 12-31-2006 at 11:38 AM.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> VC++.NET puts in a lot of other namespaces like System, System:: Data, System:: Drawing, etc...

    Are you trying to write a simple C++ application? If so, you need to create an empty Win32 Console Application project. Otherwise, the VC++ .NET IDE will add in stuff from its Managed C++ or C++/CLI variants that you don't want. So create a new project and select Win32 Console Application, check the Empty Project box on the Application Settings page of the new project dialog, and then add your code to a new file in that new project.

    If you are trying to do C++/CLI or managed C++, then I'm not sure how well you can mix it with standard C++.

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    9
    Well, I need a windows application, not a console project, and I don't know how to create controls without using managed C++.NET, you can't use the drag and drop functionality of Visual Studios to add controls which is the *only* reason I would ever use Visual Studios. I wish I could find a tutorial which explained how to do that in another compiler like Dev, but I have yet to find a good Windows tutorial that teaches how to create and use controls in C++. Does anyone know of any other compilers which uses a drag and drop IDE for C++?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Console C++ to full Windows
    By foxon177 in forum Windows Programming
    Replies: 5
    Last Post: 05-12-2008, 09:37 PM
  2. Question about console and windows programming
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 06-22-2002, 05:46 AM
  3. multiple console windows
    By gordy in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 02-13-2002, 11:05 PM
  4. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM
  5. windows dos console
    By dune911 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-16-2002, 11:30 PM