[urgent newbie] input streams problem with .NET

Discussion in 'C' started by kkyeung, May 3, 2006.

  1. kkyeung

    kkyeung New Member

    Joined:
    May 3, 2006
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    I'm now doing a project, and what I need to do is firstly read a txt file using i/o stream. I've include the lib and since I need to do it in the .NET form (header) and I want to make it such that when I click the button, it will do the file read-in.
    But I cannot add file declaration such things into the header, as there's no main func there. What should I do? Coz I wanna relate the file read-in to the button.
    Million thanks!!
     
  2. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    37
    Trophy Points:
    28
    Can you frame your question again. I mean I could not get what you are asking? Are you looking for button click handler to be added or what?
     
  3. kkyeung

    kkyeung New Member

    Joined:
    May 3, 2006
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    I have a form called form1.h, and respectively form1.cpp. I have the following code:
    Code:
    #include "stdafx.h"
    #include "Form1.h"
    #include <windows.h>
    #include <iostream>
    #include <fstream>
    
    using namespace fyp1;
    
    int APIENTRY _tWinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPTSTR    lpCmdLine,
                         int       nCmdShow)
    {
    	System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;
    
    	ifstream iFile("test.txt");
    
    
    	Application::Run(new Form1());
    	return 0;
    }
    I wanna add ifstream into above so that I can read-in a file, then pass the parameter into Form1(). But how can I do that? (ignore the button problem, i don't need it now)The above code cannot be compiled.
    Thanks again.
     
    Last edited by a moderator: May 5, 2006
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,336
    Likes Received:
    377
    Trophy Points:
    83
    But I see the ifstream is already there.
    Create an object of form1 with some other constructor
    What error it gives.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice