[英]Need some help converting C# method to C++
I am a C# guy who is desperately trying to learn C++ and port some old code over. 我是一名C#家伙,他拼命想学习C ++并将一些旧代码移植过来。 Been doing OK so far but the following method has me stumped.
到目前为止一直在行,但以下方法让我难过。 If anyone could give me some pointers (sorry for pun) I would be grateful.
如果有人能给我一些指示(对不起双关语),我将不胜感激。
C# method: C#方法:
public static string crappyEncryption(String userKey)
{
StringBuilder eStr = new StringBuilder();
String key1 = "somehorriblelongstring";
String key2 = "someotherhorriblelongstring";
for (int i = 0; i < userKey.Length; i++)
{
eStr.Append(key2[key1.IndexOf(userKey[i])]);
}
return encodeTo64(eStr.ToString());
}
encodeTo64
is a local method which I have solved in C++. encodeTo64
是我用C ++解决的本地方法。 This weird method (if you were wondering) was a small encryption method I came up with that we could use mobile cross platform for non-essential string encryption. 这种奇怪的方法(如果你想知道)是我提出的一种小型加密方法,我们可以使用移动跨平台进行非必要的字符串加密。
Thanks very much 非常感谢
Not gonna give you the whole code, but some pointers: 不会给你整个代码,但一些指针:
StringBuilder
can be substituted by a std::stringstream
. StringBuilder
可以用std::stringstream
代替。 String
is a std::string
String
是一个std::string
length()
, find()
and operator[]
. length()
, find()
和operator[]
。 std::stringstream
has operator <<
for Append
. std::stringstream
有operator <<
for Append
。 ToString
is std::stringstream::str()
. ToString
是std::stringstream::str()
。 userKey
by reference. userKey
。 All concepts you don't understand can easily be found with a google search. 您可以通过Google搜索轻松找到所有您不理解的概念。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.