C++错误:"Using obsolete binding"



我的编译器不喜欢以下代码的几件事。任何帮助非常感谢。随意批评我,因为我是一个编程n00b。我知道你们可能很苛刻。

// Method 2, the additive swap, explained inside. 
void strrev2(std::string& str) { 
    unsigned len = str.size(); 
    for (unsigned i = 0, j = len - 1; i < j; i++, j--) { 
        short a = (int)str[i]; // a is the ASCII value of the i-th character of the string
        short b = (int)str[j]; // b is the ASCII value of the j-th character of the string
        //             Current value of a        Current value of b
        a = a + b; //      a + b                         b        
        b = a - b; //      a + b                         a
        a = a - b; //        b                           a
    }
    str[i] = (char)a;
    str[j] = (char)b;
} 
i,j,a,b

循环之外不可用for但您正在尝试for循环之外访问它们。您可以考虑在循环内移动str[i] = (char)a;

for (unsigned i = 0, j = len - 1; i < j; i++, j--) { 
  ....
  ...
  str[i] = (char)a;
  str[j] = (char)b;   
}

最新更新