中文字符占两字节的证明(三分

Qyee16 2011-11-29 06:00:32


#include <string>
#include <iostream>

int main(int argc, char* argv[])
{
string str("中科院一个u盘买了6428元-----------------------------------------鼓掌");
unsigned len = str.length();

const unsigned line = 10;
string tmp;

unsigned times = 0;
unsigned timess = len % line;
if(timess == 0)
{
times = len / line;
}
else
{
timess = len / line + 1;
}


string tmp;
int currPos = 0;
for(unsigned i = 0; i < times ; ++i)
{
tmp = str.substr(currPos, lineNume);
currPos += lineNume;
cout<< tmp <<endl;
tmp.clear();
}
getchar();
return 0;
}





...全文
115 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
Qyee16 2011-12-01
  • 打赏
  • 举报
回复
我宣布,csdn出现大bug 我给分,在给分时出现多处 群主删除回复内容,而且给分后发现 被给分人都是0分。。。。。。。。。。。。。。。。。。。
duke56 2011-11-29
  • 打赏
  • 举报
回复
#include <string>
#include <iostream>
using namespace std;

//看来LZ确实加晕了,这里的(打成中文的了
int main(int argc, char* argv[])
{
string str("中科研究院买了一个128M的惠普内存条6428------------------鼓掌");
unsigned len = str.length();
const unsigned line = 10;
string tmp;

unsigned times = 0;
unsigned timess = len % line;

if(timess == 0)
{
times = len / line;
}
else
{
timess = len / line + 1;
}

// string tmp;//和上边的重定义了
int currPos = 0;
for(unsigned i = 0; i < times ; ++i)
{
tmp = str.substr(currPos, line);
currPos += line;//少了个分号
cout<< tmp <<endl;
tmp.clear();//不知道是不是我的编译问题,提示是找不到这个成员函数
}
getchar();
return 0;
}
xxwy89 2011-11-29
  • 打赏
  • 举报
回复
很有意思的哦
Qyee16 2011-11-29
  • 打赏
  • 举报
回复


#include <string>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
string str("中科研究院买了一个128M的惠普内存条6428------------------鼓掌");
unsigned len = str.length();
const unsigned line = 10;
string tmp;

unsigned times = 0;
unsigned timess = len % line;

if(timess == 0)
{ times = len / line; }
else
{ timess = len / line + 1; }

string tmp;
int currPos = 0;
for(unsigned i = 0; i < times ; ++i)
{
tmp = str.substr(currPos, line);
currPos += line
cout<< tmp <<endl; tmp.clear();
}
getchar();
return 0;
}


不好意思,又是一个bug ---------加班加晕了 ,还好没把自己项目的代码加进来。。。。。

完整版
Karl_S 2011-11-29
  • 打赏
  • 举报
回复
对比一下就行!

程序:

#include <iostream>
#include <string>
int main()
{
char *p="我",*q="我是太阳神";
int count1=0,count2=0;
while(*p!='\0')
{count1++;
p++;
}
while(*q!='\0')
{count2++;
q++;
}
cout<<count1<<endl;
cout<<count2<<endl;
}

output:
2
10



duke56 2011-11-29
  • 打赏
  • 举报
回复
而且tmp重定义

tmp.clear();?
Qyee16 2011-11-29
  • 打赏
  • 举报
回复
#include <string>
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
string str("中科研究院买了一个128M的惠普内存条6428------------------鼓掌");
unsigned len = str.length();
const unsigned line = 10;
string tmp;
unsigned times = 0;
unsigned timess = len % line;
if(timess == 0) { times = len / line; }
else { timess = len / line + 1; }
string tmp;
int currPos = 0;
for(unsigned i = 0; i < times ; ++i)
{
tmp = str.substr(currPos, lineNume);
currPos += lineNume;
cout<< tmp <<endl; tmp.clear();
}
getchar();
return 0;
}

duke56 2011-11-29
  • 打赏
  • 举报
回复
LZ的代码好像有错误哦...

lineNume不知道是从何而来

还有main后边的是中文的括号
Qyee16 2011-11-29
  • 打赏
  • 举报
回复

#include <string>
#include <iostream>

using namespace std;
int main(int argc, char* argv[])
{
string str("中科研究院买了一个128M的惠普内存条6428------------------鼓掌");
unsigned len = str.length();
const unsigned line = 10;
string tmp;
unsigned times = 0;
unsigned timess = len % line;
if(timess == 0) { times = len / line; }
else { timess = len / line + 1; }
string tmp;
int currPos = 0;
for(unsigned i = 0; i < times ; ++i)
{
tmp = str.substr(currPos, lineNume);
currPos += lineNume;
cout<< tmp <<endl; tmp.clear();
}
getchar();
return 0;
}




唉 ,用记事本写代码 就是不好弄,写了俩bug

一个业务的是:中科研究院买了一个128M的惠普内存条6428------------------鼓掌
代码的,忘加:using namespace std;
haofang666777 2011-11-29
  • 打赏
  • 举报
回复
很久没来,楼上终于3颗星了,呵呵
[Quote=引用 3 楼 qq120848369 的回复:]
不懂。。。

这个还是看编码的。。。可以是3个,可以是4个。
[/Quote]
xunxun 2011-11-29
  • 打赏
  • 举报
回复
那要是unicode的……

ps:lz你好闲
qq120848369 2011-11-29
  • 打赏
  • 举报
回复
不懂。。。

这个还是看编码的。。。可以是3个,可以是4个。

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧