我在我的代碼中設置了一個多選函數,允許我打開多個「.txt」格式的文件。這裏是問題,我打算如何通過OpenFileDialog打開所有這些選定的文件?下面的代碼和「for each」這行代碼,當我使用System :: Diagnostics :: Debug時,它只顯示來自文件的數據,而其他文件的數據丟失。我應該如何修改「for each」之後的代碼?任何人都可以提供一些建議或建議?所選文件爲1_1.txt,2_1.txt,3_1.txt。感謝您的回覆,並提前致謝。如何在OpenFileDialog中單擊打開後讀取多個文件?
這是我寫的代碼,
Stream^ myStream;
OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
openFileDialog1->InitialDirectory = "c:\\";
openFileDialog1->Title = "open captured file";
openFileDialog1->Filter = "CP files (*.cp)|*.cp|All files (*.*)|*.*|txt files (*.txt)|*.txt";
openFileDialog1->FilterIndex = 2;
openFileDialog1->Multiselect = true;
if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
array<String^>^ lines = System::IO::File::ReadAllLines(openFileDialog1->FileName);
for each (String^ line in lines) {
//?????
System::Diagnostics::Debug::WriteLine("",line);
}
}
這不是C++ – 2013-03-22 17:38:19
@ user931794這是C++/CLI – 2013-03-22 17:41:06
肯你有'標記C#' – MethodMan 2013-03-22 17:41:48