3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#include "stdafx.h"
#include <string>
#include <iostream>
using
namespace
std;
int
_tmain(
int
argc, _TCHAR* argv[])
{
string s =
"你好优快云,我的"
;
string t;
for
(
int
i=0; i<s.length(); i++)
{
if
(s[i]<255 && s[i]>0)
//扩充的ASCII字符范围为0-255,如是,处理一个字节
{
t.append(s.substr(i,1));
t.append(
"/"
);
}
else
//<0,>255的是汉字,处理两个字节
{
t.append(s.substr(i,2));
t.append(
"/"
);
++i;
}
}
cout << t << endl;
//输出符合要求
return
0;
}
希望能为需要的朋友解决问题,
|