2012-07-03 4 views
2

나는 다음과 같은 문제 출력은C++ 특수 문자

#include <iostream> 
#include <stdio.h> 
#include <string.h> 

int main(){ 
    string data = "\xd7\x91\xd7\x90" ; 

    data << data<<endl; 
} 

있습니다.

#include <iostream> 
#include <stdio.h> 
#include <string.h> 

int main(){ 
    char rrr[100]; 
    cout << "Please enter your string:" ; 
    scanf("%s",rrr); 

    cout<< rrr <<endl; 
}  

내가 입력 입력은 다음과 같습니다 \xd7\x91\xd7\x90

나는 화면에 표시되는 출력은 다음과 같습니다 \xd7\x91\xd7\x90

그래서 제 질문은 어떻게 입력 בא-\xd7\x91\xd7\x90을 변환 할 수 있습니까?

+5

당신은 입력 할 수 있습니다 "בא"직접 ... – kennytm

+1

@KennyTM , s/could/should/... – Griwes

+0

입력 문자열에있는 모든 "\ xAB"를 (char) (A * 16 + B)로 대체해야합니다. – k06a

답변

4

당신은 당신의 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'; 

를, 그것은 람 16 진수 값에 스트리밍하는 법을 배워야하는 것이 좋습니다 :

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; 
+0

좋은 해결책 !! – k06a

+0

k06a : 감사합니다 .-) –

+0

감사합니다. 그러나 도움이되지 않습니다. 이 \ xd7 \ x91 \ xd7 \ x90을 내가 변경할 수없는 html 형식에서 가져 오기 때문에 이것을 אב로 변환해야합니다. – RoiHatam