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. C / C++ / MFC
  4. Reading from a file in C++ Windows Application Forms

Reading from a file in C++ Windows Application Forms

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studiowinformshelp
5 Posts 3 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.
  • U Offline
    U Offline
    User 12967909
    wrote on last edited by
    #1

    Hello, I am working on a windows Forms Application (C++) Programm in Visual Studio 2015. I have figured out how to open a file. And read from it. But what I can't figure out is how to only read the second line or the second row from my file (.cvs file). What I am looking for is the syntax to use instead of RealAllText. I looked up the Objectkatalog. But I can't get "ReadLine" to work. My code is posted below. I really hope someone can help me :) Kind regards private: System::Void button6_Click_1(System::Object^ sender, System::EventArgs^ e) { Stream^ myStream; OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog; if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK) { if( (myStream = openFileDialog1->OpenFile()) != nullptr ) { String^ strfilename = openFileDialog1->InitialDirectory + openFileDialog1->FileName; String^ Readfile = File::ReadAllText(strfilename); Malz4->Text = Readfile; myStream->Close(); } }

    L D 2 Replies Last reply
    0
    • U User 12967909

      Hello, I am working on a windows Forms Application (C++) Programm in Visual Studio 2015. I have figured out how to open a file. And read from it. But what I can't figure out is how to only read the second line or the second row from my file (.cvs file). What I am looking for is the syntax to use instead of RealAllText. I looked up the Objectkatalog. But I can't get "ReadLine" to work. My code is posted below. I really hope someone can help me :) Kind regards private: System::Void button6_Click_1(System::Object^ sender, System::EventArgs^ e) { Stream^ myStream; OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog; if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK) { if( (myStream = openFileDialog1->OpenFile()) != nullptr ) { String^ strfilename = openFileDialog1->InitialDirectory + openFileDialog1->FileName; String^ Readfile = File::ReadAllText(strfilename); Malz4->Text = Readfile; myStream->Close(); } }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Use File.ReadAllLines Method (String) (System.IO)[^] which returns an array of strings. The string at index offset 1 is the second line of the file.

      U 1 Reply Last reply
      0
      • U User 12967909

        Hello, I am working on a windows Forms Application (C++) Programm in Visual Studio 2015. I have figured out how to open a file. And read from it. But what I can't figure out is how to only read the second line or the second row from my file (.cvs file). What I am looking for is the syntax to use instead of RealAllText. I looked up the Objectkatalog. But I can't get "ReadLine" to work. My code is posted below. I really hope someone can help me :) Kind regards private: System::Void button6_Click_1(System::Object^ sender, System::EventArgs^ e) { Stream^ myStream; OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog; if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK) { if( (myStream = openFileDialog1->OpenFile()) != nullptr ) { String^ strfilename = openFileDialog1->InitialDirectory + openFileDialog1->FileName; String^ Readfile = File::ReadAllText(strfilename); Malz4->Text = Readfile; myStream->Close(); } }

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        If ReadAllText() returns a sequence, could you then call First() twice on that sequence?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        1 Reply Last reply
        0
        • L Lost User

          Use File.ReadAllLines Method (String) (System.IO)[^] which returns an array of strings. The string at index offset 1 is the second line of the file.

          U Offline
          U Offline
          User 12967909
          wrote on last edited by
          #4

          Hey, thanks for your help but I still can't get my code to work. I typed in your suggestion but maybe I am doing a sytax error? I am a beginner so that might be the case :confused: haha And how would I get the second column out?

          L 1 Reply Last reply
          0
          • U User 12967909

            Hey, thanks for your help but I still can't get my code to work. I typed in your suggestion but maybe I am doing a sytax error? I am a beginner so that might be the case :confused: haha And how would I get the second column out?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Without seeing your code it is impossible to comment.

            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