比较包含负字符的字符串时出现令人惊讶的结果

Roy*_*Dan 5 c++ string comparison stdstring

#include "stdafx.h"
#include "iostream"
#include "string"

using namespace std;

void main()
{
    string a = "a";
    string b(1, -70); /*constructor, create a string having 1 character that its value is equal to -70*/
    cout << (b > a ? b : a);
}

//output on screen: b was printed, not a (!)
Run Code Online (Sandbox Code Playgroud)

虽然b的值小于a的值,为什么b>a?我该如何纠正这种情况?

San*_*ndy 0

将 -70 的二进制等效值视为 1 字符。