wchar_t

宽字符

#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#



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值