Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. [urgent newbie] input streams problem with .NET

[urgent newbie] input streams problem with .NET

Scheduled Pinned Locked Moved Managed C++/CLI
csharphelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kkyeung
    wrote on last edited by
    #1

    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!!

    S 1 Reply Last reply
    0
    • K kkyeung

      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!!

      S Offline
      S Offline
      Saksida Bojan
      wrote on last edited by
      #2

      kkyeung wrote:

      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.

      The main func only show one form. Then the form is handling evrything else. declare in a forn inside class of the form.

      kkyeung wrote:

      I've include the lib and since I need to do it in the .NET form

      you don't need to include lib. you can use .net: using namespace System::IO; StreamReader; -- modified at 2:39 Thursday 4th May, 2006

      K 1 Reply Last reply
      0
      • S Saksida Bojan

        kkyeung wrote:

        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.

        The main func only show one form. Then the form is handling evrything else. declare in a forn inside class of the form.

        kkyeung wrote:

        I've include the lib and since I need to do it in the .NET form

        you don't need to include lib. you can use .net: using namespace System::IO; StreamReader; -- modified at 2:39 Thursday 4th May, 2006

        K Offline
        K Offline
        kkyeung
        wrote on last edited by
        #3

        I have a form called form1.h, and respectively form1.cpp. I have the following 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. -- modified at 15:09 Thursday 4th May, 2006

        S 1 Reply Last reply
        0
        • K kkyeung

          I have a form called form1.h, and respectively form1.cpp. I have the following 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. -- modified at 15:09 Thursday 4th May, 2006

          S Offline
          S Offline
          Saksida Bojan
          wrote on last edited by
          #4

          As i told you, you will need StreamReader. It is .NET class, not MFC or other, so there you musn't include iostream, fstream and windows.h. Include file Windows.h often couses compile problem in .Net framework project. so remove all these include you will Need to add in form1.h file not in form1.cpp. using namespace System::IO;

          public ref class Form1: public System::Windows::Forms::Form // This is a class of a form. ref command is in .NET 2.0 if you use .NET 1.1 then it is __gc
          {
          public:
          Form1(void) ... // Default consrtuctor
          ...
          Private: StreamReader ^streamFile;
          Private: String ^streamReadLine;
          ...
          public: ReadFile(void)
          {
          streamFile = File::OpenText("test.txt");
          while (streamFile->EndOfStream != true)
          {
          streamReadLine = streamFile->ReadLine();
          }
          }
          };

          If you still don't know, at least tell me witch .net framework you are using.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups