为什么人物在处理他们之后会出现像

Why characters shows up like � after dealing with them?

本文关键字:之后 他们 人物 处理 为什么      更新时间:2023-10-16

我正在做一种加密算法,但我有一个可怕的问题,当处理一些特殊字符,如" "," "。

每当我在内存或类似的地方进行复制时,这个问题就会出现。我写了一小段代码来解释它:

#include<string.h>
#include<iostream>
using namespace std;
int main() {
    char ar[]="à";
    char bf[]="a";
    char cd;
    cout <<"Before:n" << ar <<"t" <<bf << endl;
    cd=ar[0];
    ar[0]=bf[0];
    bf[0]=cd;
    cout <<"After:n" << ar  <<"t" <<bf << endl;
}

由于我对此知之甚少,我无法解决这个问题。我怎样才能解决这个问题?

据我所知,我们无法在ascii码中找到字符à。因此,使用wchar_t代替char。因为char只有8位,只能处理256个不同的字符。

im dealing with arrays in ma code ...and using wchar_t to store the char in cd didn't help

在这种情况下使用wchar_t数组

声明wchar_t字符串

wchar_t wptr[] = L"Your String";

声明wchar_t char

`wchar_t wc=L'A';

声明一个wchar_t char数组

 `wchar_t aa[]={L'A',L'B'};`
所以你的代码变成了

   #include<string.h>
#include<iostream>
using namespace std;
int main() {
wchar_t ar[]=L"à";
wchar_t bf[]=L"a";
wchar_t cd;
cout <<"Before:n" <<ar <<"t" <<bf <<endl;
cd=ar[0];
ar[0]=bf[0];
bf[0]=cd;
cout <<"After:n" <<ar  <<"t" <<bf <<endl;
}

这就解决了问题

如果在Windows操作系统上从DOS命令提示符运行此程序,则必须将命令窗口设置为使用与ANSI兼容的活动代码页。下面的代码页在我的系统上工作:

chcp 1252

运行程序前输入chcp命令