按下按钮,在文件中搜索一行 condition:输入的单词与字符串中的第一个单词匹配 通过按dataGridView1中的按钮只添加一次。他第二次写“问题阅读文件”。 为什么代码有效并且中断?
private: System::Void addproductbutton_Click(System::Object^ sender, System::EventArgs^ e) {
barcode = addproducttextBox->Text;
flag = false;
String^ fileName = "C:\\Users\\sfilc\\Desktop\\products.txt";
StreamReader^ din = File::OpenText(fileName);
try
{
String^ str;
while ((str = din->ReadLine()) != nullptr || flag != true)
{
FindInString(str, barcode);
}
din->Close();
}
catch (Exception^ e)
{
if (dynamic_cast<FileNotFoundException^>(e))
{
addproducttextBox->Text += "file not found";
addproducttextBox->Text += Environment::NewLine;
}
else
{
addproducttextBox->Text += "problem reading file";
addproducttextBox->Text += Environment::NewLine;
}
}
}
void FindInString(String^ s, String^ substring)
{
int result = s->IndexOf(substring);
if (result != -1) {
row->CreateCells(dataGridView1);
for (int i = 0; i < s->Split(L' ')->Length; i++)
row->Cells[i]->Value = s->Split(L' ')[i];
dataGridView1->Rows->Add(row);
addproducttextBox->Text = "";
flag = true;
}
}
追踪
'Cash2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\win32u.dll'. Cannot find or open the PDB file.
'Cash2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Cannot find or open the PDB file.
'Cash2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'. Cannot find or open the PDB file.
'Cash2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\version.dll'. Cannot find or open the PDB file.
'Cash2.exe' (Win32): Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll'. Cannot find or open the PDB file.
'Cash2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr120_clr0400.dll'. Cannot find or open the PDB file.
'Cash2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\psapi.dll'. Cannot find or open the PDB file.
'Cash2.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\psapi.dll'
'Cash2.exe' (Win32): Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\a973fcfc0c7b60badfdb6142dfc74fa8\mscorlib.ni.dll'.
'Cash2.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Cash2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Cannot find or open the PDB file.
'Cash2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\uxtheme.dll'. Cannot find or open the PDB file.
'Cash2.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\sfilc\source\repos\Cash2\Debug\Cash2.exe'. Symbols loaded.
'Cash2.exe' (Win32): Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clrjit.dll'. Cannot find or open the PDB file.
'Cash2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. Cannot find or open the PDB file.
'Cash2.exe' (Win32): Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\diasymreader.dll'. Cannot find or open the PDB file.
'Cash2.exe' (Win32): Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System\f4d090fc4e195abf9ee82df5fdaf5dfa\System.ni.dll'.
'Cash2.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Cash2.exe' (Win32): Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Drawing\fa546047328c4bd2b920f430344f7471\System.Drawing.ni.dll'.
'Cash2.exe' (Win32): Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Windows.Forms\15aeb75be4c878003bd1bfb744ebbd8f\System.Windows.Forms.ni.dll'.
'Cash2.exe' (CLR v4.0.30319: Cash2.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Cash2.exe' (CLR v4.0.30319: Cash2.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Cash2.exe' (Win32): Loaded 'C:\Windows\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.17134.48_none_7c26c75f64c9226c\GdiPlus.dll'. Cannot find or open the PDB file.
'Cash2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. Cannot find or open the PDB file.
'Cash2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\DWrite.dll'. Cannot find or open the PDB file.
'Cash2.exe' (Win32): Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Core\6ebc1f8ebf968f3631650d4c73990aa2\System.Core.ni.dll'.
'Cash2.exe' (Win32): Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Configuration\45be38b7aa257c1b1ad2a9acd527587e\System.Configuration.ni.dll'.
'Cash2.exe' (CLR v4.0.30319: Cash2.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Cash2.exe' (CLR v4.0.30319: Cash2.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Cash2.exe' (Win32): Loaded
'C:\的Windows \组件\ NativeImages_v4.0.30319_32 \的System.Xml \ e62beac983ec7251e0b3e9700818c994 \ System.Xml.ni.dll'。 'Cash2.exe'(CLR v4.0.30319:Cash2.exe):已加载'C:\ WINDOWS \ Microsoft.Net \ assembly \ GAC_MSIL \ System.Xml \ v4.0_4.0.0.0__b77a5c561934e089 \ System.Xml.dll'。跳过加载符号。模块已经过优化,调试器选项“Just My Code”已启用。 'Cash2.exe'(Win32):加载'C:\ Windows \ SysWOW64 \ shell32.dll'。无法找到或打开PDB文件。 'Cash2.exe'(Win32):加载'C:\ Windows \ SysWOW64 \ cfgmgr32.dll'。无法找到或打开PDB文件。 'Cash2.exe'(Win32):加载'C:\ Windows \ SysWOW64 \ SHCore.dll'。无法找到或打开PDB文件。 'Cash2.exe'(Win32):加载'C:\ Windows \ SysWOW64 \ windows.storage.dll'。无法找到或打开PDB文件。 'Cash2.exe'(Win32):加载'C:\ Windows \ SysWOW64 \ profapi.dll'。无法找到或打开PDB文件。 'Cash2.exe'(Win32):加载'C:\ Windows \ SysWOW64 \ powrprof.dll'。无法找到或打开PDB文件。 'Cash2.exe'(Win32):加载'C:\ Windows \ SysWOW64 \ fltLib.dll'。无法找到或打开PDB文件。 'Cash2.exe'(Win32):加载'C:\ Windows \ SysWOW64 \ bcrypt.dll'。无法找到或打开PDB文件。 'Cash2.exe'(Win32):加载'C:\ Windows \ SysWOW64 \ cryptsp.dll'。无法找到或打开PDB文件。 'Cash2.exe'(Win32):加载'C:\ Windows \ SysWOW64 \ rsaenh.dll'。无法找到或打开PDB文件。