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