C++如何生成随机字符串,Unicode字符集

xfoolish 2013-12-05 06:49:45
大家好~
我想生成一批随机字符串,用于测试一个字符串处理的程序,
要求字符集为所有有效的Unicode字符。

我使用的数据类型为标准库的string类型,谁有好的想法,
谢谢~
...全文
525 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ooolinux 2013-12-06
  • 打赏
  • 举报
回复
看看,我也想知道,mark。
赵4老师 2013-12-06
  • 打赏
  • 举报
回复
Character Classification Each of these routines tests a specified single-byte character, wide character, or multibyte character for satisfaction of a condition. (By definition, the ASCII character set is a subset of all multibyte-character sets. For example, Japanese katakana includes ASCII as well as non-ASCII characters.) Generally these routines execute faster than tests you might write. For example, the following code executes slower than a call to isalpha(c): if ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')) return TRUE; Character-Classification Routines Routine Character Test Condition isalnum, iswalnum, _ismbcalnum Alphanumeric isalpha, iswalpha, _ismbcalpha Alphabetic __isascii, iswascii ASCII iscntrl, iswcntrl Control __iscsym Letter, underscore, or digit __iscsymf Letter or underscore isdigit, iswdigit, _ismbcdigit Decimal digit isgraph, iswgraph, _ismbcgraph Printable other than space islower, iswlower, _ismbclower Lowercase _ismbchira Hiragana _ismbckata Katakana _ismbclegal Legal multibyte character _ismbcl0 Japan-level 0 multibyte character _ismbcl1 Japan-level 1 multibyte character _ismbcl2 Japan-level 2 multibyte character _ismbcsymbol Non-alphanumeric multibyte character isprint, iswprint, _ismbcprint Printable ispunct, iswpunct, _ismbcpunct Punctuation isspace, iswspace, _ismbcspace White-space isupper, iswupper, _ismbcupper Uppercase iswctype Property specified by desc argument isxdigit, iswxdigit Hexadecimal digit mblen Return length of valid multibyte character; result depends on LC_CTYPE category setting of current locale
xiaohuh421 2013-12-06
  • 打赏
  • 举报
回复
可以写一个表, 里面存放了数字和字母的ASCII, 然后使用随机函数取得这些字符, 然后连接成串即可. 如果还想随机汉字, 那么可以先了解一下GB2312编码, 然后转换成UNICODE即可.
aiyaya730 2013-12-06
  • 打赏
  • 举报
回复
unicode 是32位,随机生一组 [0 , 2^64 -1] 区间的数字就可以当成一个 unicode 字符串了。 另外标准库好像有 std::wstring 专门支持宽字符集的
asd8532 2013-12-05
  • 打赏
  • 举报
回复
标记一下,希望有人回答

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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