首先获取keymap。将键盘上按顺序都打一遍,记录在map中,此后通过map匹配即可

#include<iostream>
#include<string>
#include<map>

using namespace std;


int main() {
    string str,result,tmp;
    map<char, char> keymap;
    result= "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
    char ch=' ';
    for (int i = 1; i < result.size(); ++i)
        keymap[result[i]] = result[i - 1];
    keymap[ch] = ch;
    while (getline(cin,str)) {
        tmp = str;
        for (int j = 0; j < str.size(); ++j)
            tmp[j] = keymap[str[j]];
        cout << tmp;
        if (cin.get() == '\n')
            break;
    }
    cout << endl;
    return 0;
}