I get the error:'Input string was not in a correct format'
This code, when I use it in C#, works fine, but I translated it myself, so there could be an error there. (I normally use this for text encryption, as it is short and quick)
This is my C++ code:
void encrypt()
{
string psw = "mystring";
System::String^ encr;
int tot;
int num;
int lng = psw.size();
char pswchar[1024];
strcpy_s(pswchar, psw.c_str());
System::String^ istr;
for (int i = 0; i < lng; i++)
{
{
ostringstream ss;
ss << pswchar[i];
istr = gcnew System::String(ss.str().c_str());
}
num = int::Parse(istr) + 15; // << I get the error here
tot += num;
}
ostringstream convert;
convert << tot;
encr = gcnew System::String(convert.str().c_str());
File::WriteAllText("C:\myfolder\mypath.txt", encr);
}
This is my C# Code:
void encrypt()
{
string psw = "mystring";
string encr;
char[] pswchar = psw.ToCharArray();
for (int i = 0; i < pswchar.Length; i++)
{
int num = Convert.ToInt32(pswchar[i]) + 15;
string cvrt = Convert.ToChar(num).ToString();
encr += cvrt;
}
}
int::Parseis suspicious. You should not convert C# to C++ but think and code in C++11! C# and C++ are different languages (like English and German are).