简体   繁体   English

需要一些帮助将C#方法转换为C ++

[英]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: 不会给你整个代码,但一些指针:

  • a StringBuilder can be substituted by a std::stringstream . StringBuilder可以用std::stringstream代替。
  • a String is a std::string String是一个std::string
  • it has the method length() , find() and operator[] . 它有方法length()find()operator[]
  • std::stringstream has operator << for Append . std::stringstreamoperator << for Append
  • ToString is std::stringstream::str() . ToStringstd::stringstream::str()
  • you'll want to pass 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM