21. 在 C++ 中如何将std::string转换为unsigned char* ?
Posted by haifeng on 2018-03-07 22:25:34 last update 2018-03-07 22:25:34 | Answers (0) | 收藏
在 C++ 中如何将std::string转换为unsigned char* ?
反之如何将 unsigned char* 转换为 std::string ?
Posted by haifeng on 2018-03-07 22:25:34 last update 2018-03-07 22:25:34 | Answers (0) | 收藏
在 C++ 中如何将std::string转换为unsigned char* ?
反之如何将 unsigned char* 转换为 std::string ?
Posted by haifeng on 2017-06-21 08:49:05 last update 2017-06-21 08:49:05 | Answers (2) | 收藏
使用 c++ 打印向量
Posted by haifeng on 2015-09-19 22:00:33 last update 2015-09-19 22:00:33 | Answers (0) | 收藏
http://blog.csdn.net/stereohomology/article/details/11980917
Posted by haifeng on 2015-06-13 14:16:33 last update 2015-06-13 14:16:33 | Answers (0) | 收藏
C++ 传递参数有三种不同的方式
1. 按常量引用调用(call by constant reference)
2. 按值调用(call by value)
3. 引址调用(call by reference)
Posted by haifeng on 2015-03-11 07:59:58 last update 2015-03-11 07:59:58 | Answers (0) | 收藏
Posted by haifeng on 2015-01-12 22:59:18 last update 2019-03-04 09:39:17 | Answers (0) | 收藏
方法一:
使用传统的方法判断, 即对于 $N > 3$, 用 $i=1,3,\ldots, [\sqrt{N}]$ 去试除 $N$, 如果都无法除尽, 则 $N$ 是素数.
不过当 $N$ 很大时, 这个算法效率很低下.
方法二:
首先将前 1000 个或 1,000,000 个素数读入内存, 采用二叉查找树的结构.
利用查找方式判定一个整数(在此范围内)是否是素数.
[评论] 这个需要预先得到这 1,000,000 个素数. 即使不考虑这部分所耗的时间, 后续使用二叉查找树, 查找 $N$ 是否在其中也需要花费 $\log_2 N$ 的时间(指时间复杂度).
Posted by haifeng on 2015-01-12 22:24:21 last update 2015-01-12 22:24:21 | Answers (0) | 收藏
求一个整数其十进制表达式中的各个数字之和
Posted by haifeng on 2014-03-06 09:27:38 last update 2014-03-06 09:34:19 | Answers (0) | 收藏
打开文件 stdlib.h (如果安装的是 Code::Blocks, 则位于 C:\Program Files\CodeBlocks\MinGW\include 中)
cstdlib, ctime 等位于 C:\Program Files\CodeBlocks\MinGW\lib\gcc\mingw32\4.7.1\include\c++
/* * RAND_MAX is the maximum value that may be returned by rand. * The minimum is zero. */ #define RAND_MAX 0x7FFF _CRTIMP int __cdecl __MINGW_NOTHROW rand (void); _CRTIMP void __cdecl __MINGW_NOTHROW srand (unsigned int);
References:
Posted by haifeng on 2014-03-02 14:25:04 last update 2014-03-02 14:25:04 | Answers (0) | 收藏
C++ 中 enum 的使用, 例如
enum {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday}
则整数常量 Sunday, Monday, Tuesday,..., Saturday 按默认方式依次被赋值为 0,1,2,...,6.
也可以为枚举命名. 例如
enum Months{January, February, March, April, May, June, July, August, September, October, November, December}
Posted by haifeng on 2013-03-29 00:15:30 last update 2013-03-29 00:15:30 | Answers (0) | 收藏