[英]C++ special characters
I have the following problem 我有以下问题
#include <iostream>
#include <stdio.h>
#include <string.h>
int main (){
string data = "\xd7\x91\xd7\x90" ;
data << data<<endl;
}
The output is: בא 输出为:בא
But with an input. 但是有输入。
#include <iostream>
#include <stdio.h>
#include <string.h>
int main (){
char rrr[100];
cout << "Please enter your string:" ;
scanf("%s",rrr);
cout<< rrr <<endl;
}
The input I type is: \\xd7\\x91\\xd7\\x90
我输入的输入是:
\\xd7\\x91\\xd7\\x90
The output I see on the screen is: \\xd7\\x91\\xd7\\x90
我在屏幕上看到的输出是:
\\xd7\\x91\\xd7\\x90
So my question is how can I convert the input \\xd7\\x91\\xd7\\x90
to בא
? 所以我的问题是如何将输入
\\xd7\\x91\\xd7\\x90
转换为בא
?
You can change your scanf statement: 您可以更改scanf语句:
int a, b, c, d;
if (scanf("\\x%x\\x%x\\x%x\\x%x", &a, &b, &c, &d) == 4)
// a, b, & c have been read/parsed successfully...
std::cout << (char)a << (char)b << (char)c << (char)d << '\n';
Still, it's better to learn to stream in hex values ala: 不过,最好学习以十六进制值流式传输ala:
char backslash, x;
char c;
while (std::cin >> backslash >> x >> std::hex >> c && backslash == '\\' && x == 'x')
// or "for (int i = 0; i < 4 && std::cin >> ...; ++i)" if you only want four
std::cout << c;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.