Reading from a file in C++ Windows Application Forms
-
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(); } }
-
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(); } }
-
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(); } }
If
ReadAllText()
returns a sequence, could you then callFirst()
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
-
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.
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?
-
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?