我要做的是创建一个加密工具。它将文件转换为字符串。然后该字符串将被加密。但是,在将文件转换为字符串并再次保存该文件时(出于测试目的),返回的文件与原始文件不同,即使在更改扩展名后也无法打开。请帮忙:
String^ fileNME = textBox1->Text; //File is selected via fileopendialog and then copied to TextBox1
//Convert from System::String to std::string. result is actually a string that holds the filename.
string result("a");
result = marshal_as<std::string>( fileNME );
string fileToEncryptasString;
fileToEncryptasString = fileToString(result);
myfile.open ("filecopy.txt");
myfile << fileToEncryptasString;
myfile.close();
//File to String function is this:
string fileToString(const string& filename)
{
ifstream file(filename, ios::binary);
if (!file) return "";
string str(istreambuf_iterator<char>(file),
(istreambuf_iterator<char>()));
return str;
}