string的find函数找不到"\"转义字符,需要再添加一个"\\",这样就可以找到了
#include<cstdint> #include<string> #include<iostream> using namespace std; int main() { string s1 = "`1234567890-QWERTYUIOP[]ASDFGHJKL;ZXCVBNM,."; string s2 = "1234567890-=WERTYUIOP[]\\SDFGHJKL;'XCVBNM,./"; string s3 ;//= "O S, GOMR YPFSU/";//转义字符的使用 //cin>>s3; int x ; while(x = getchar() ) { if(x == EOF || x == '\n') break; if(x == ' ') { printf(" "); continue; } int pos = s2.find(x); printf("%c",s1[pos]); } }