读取文件流并转换为字符数组时出错
Visual C++ Error Reading Filestream and Converting to Array of Characters
首先这里是我试图得到工作的代码-
private: System::Void openToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
OpenFileDialog^ dlg = gcnew OpenFileDialog();
dlg->Filter = "Text Files|*.txt";
String^ stream;
if(dlg->ShowDialog()==Windows::Forms::DialogResult::OK)
{
txtOutput->Text = System::IO::File::ReadAllText(dlg->FileName);
char* num = (char*)(void*)Marshal::StringToHGlobalAnsi(stream); //Convert string to array of char
for (int i=0;i<stream->Length;++i) //ERRONEOUS LINE!!
{
num[i] = num[i] ^ key; //DECRYPT
}
String^ orig_stream = gcnew String(num);
txtOutput->Text = orig_stream;
}
}
我试图打开一个已经加密的文件。该程序编译时没有任何错误,但在运行时,它给了我以下错误,选项是中断,继续或中止:
An unhandled exception of type 'System.NullReferenceException' occurred in Project_Targaryen.exe
Additional information: Object reference not set to an instance of an object.
错误指向for循环行。任何帮助都是感激的!
stream
在for循环中使用之前不与对象关联。
相关文章:
- 指向指向字符数组的指针数组的指针
- 比较字符数组
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- 使用无符号字符数组有效存储内存
- 错误:字符数组的初始值设定项太多
- 对字符数组中的元素执行逐位操作
- C++ 无法在字符数组中使用 for 循环打印字母模式
- 如何在 C++ 中从文件中读取字符数组(带有一些空格)
- C++ 传递二维字符数组
- 无法在 C++ 中输入字符数组
- 字符数组中的元素数
- 我的目标是编写一个程序来计算和存储字符串在字符数组中出现的位置
- 使用字符数组作为 Map 中的键
- C++:__aligned(__alignof__) 导致字符数组数据出现问题?
- 按顺序声明的字符数组重叠
- 在 C++ 中字符串的大小与字符数组的大小
- 寻找一种更好的方法来表示无符号字符数组
- 如何打印 2D 字符数组C++
- 从字符数组的元素中减去'a'是什么意思
- 我是否不正确地集中了这些字符数组?