宽字符
#include<iostream>
#include<locale>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
setlocale(LC_ALL, "chs");
int i;
wchar_t a[10];//10个汉字
wscanf(L"%s",a);
wchar_t b;
getchar();
wscanf(L"%c",&b);
for(i=0;i<wcslen(a);i++){//中间那个wcslen(a)是获取汉字串a的长度,也就是几个汉字,类似于strlen()
if(a[i]==b&&i>0)
{
swap(a[i-1],a[i]);
}
}
wprintf(L"%s\n",a);
return 0;
}
/*wchar_t就相当于汉字数据类型吧
读入: wscanf(L"%c",&b);//当个汉字读入,注意wscanf(L" ")
wscanf(L"%s",a);//一串中文读入
输出: wprintf(L"%c",b);
wprintf(L"%s",a);*/
/*#include<iostream>
#include<locale>
using namespace std;
int main(){
setlocale(LC_ALL,"chs");//设置本地语言为中文简体,该设置要引入头文件locale
wchar_t ch[]=L"中华";//定义宽字符,大写字母L表示告诉c++编译器为“中”分配两个字节的空间
wcin>>ch;
wcout<<ch<<endl;//使用wcout代替cout输出宽字符
return 0;
}*//*
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
setlocale(LC_ALL, "chs");
wchar_t *ws = L"中文input";
int len = wcslen(ws);
//wchar_t wc[]=L"i";
//wchar_t *find = wcschr(ws,wc);
for(int i=0; i<len; i++){
wprintf(L"%c ", ws[i]);
}
return 0;
}*/
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
setlocale(LC_ALL, "chs");
wchar_t *ws = L"中文input";
int len = wcslen(ws);
for(int i=0; i<len; i++){
wprintf(L"%c ", ws[i]);
}
wcout<<endl;
wchar_t p[105];
wchar_t a;
wscanf(L"%c", &a);
wscanf(L"%s", p);
wprintf(L"a = %c\n", a);
wprintf(L"p = %s\n", p);
wprintf(L"p = %c\n", p[2]);
wchar_t temp=a;
a=p[2];
p[2]=temp;
cout<<endl;
wprintf(L"a = %c\n", a);
wprintf(L"p = %s\n", p);
wprintf(L"p = %c\n", p[2]);
return 0;
}
http://www.360doc.com/content/13/0307/17/5169677_270001056.shtml
http://baike.baidu.com/view/2063825.htm
http://blog.csdn.net/xlf13872135090/article/details/8237603#userconsent#