CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2010
    Posts
    6

    Reading a text file

    hi all
    can u pls help me i want to do an event that reads the second line of a text file and put it in text box1
    can u pls help me
    it's vb.net code
    is
    Dim s As String() = System.IO.File.ReadAllLines("conn")
    TextBox1.Text = s(2)
    I want the C++ code for this
    Thanks in advance

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Reading a text file

    The C++/CLI code to read the second line of a text file into a text box, analogous to your VB .NET code, goes like this:

    Code:
      array<String ^> ^s = IO::File::ReadAllLines("conn");
      TextBox1->Text = s[1];
    Note that the index of the second line in the string array is 1 because array indices are zero-based. (And I'm pretty sure this applies to VB .NET as well.)

    One elementary problem in the translation from VB .NET or C# to C++/CLI is that, unlike these languages which take these detail under the hood, C++/CLI uses a pointer-like syntax for declaring tracking handles to reference types and accessing objects via them which comes closer to what they actually are. (IMO this is an advantage of C++/CLI but this opinion is arguable...) There are exceptions from this rule in C++/CLI, however, but I think we should ignore them for now for the sake of simplicity.

    HTH
    Last edited by Eri523; December 30th, 2010 at 08:32 PM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured