1.
size() 和 strlen()
头文件include方法:
strlen():
#include <string.h>//C #include <cstring>//C++
用法:
size():
string _Str("HelloWorld"); size_t _Size = _Str.size();//此时_Size 是 _Str的字符数,在遍历的时候要注意,首先,要用小于号,第二,不能用int i = _Size //得用size_t i = _size
template<typename T> map<T,T> _Map; size_t _Size = _Map.size()//此时_Size 是 _Map 的项数
strlen():
string _Str("HelloWorld"); size_t _Size = strlen(_Str.c_str());//这种方法和size差不多,但是不太推荐,还是建议用size(),应该改成以下内容: char* _str = new char;//原理和string基本差不多,指针换char _str = (char*)"HelloWorld";//必须转char*,字符串本来的定义是const char* size_t _size = strlen(_str);
2.
strtol(),atoi()
注释:itoa()(安全版本_itoa_s()) 在某些版本没有,所以不解释
头文件include方法:
#include <stdlib.h>//C #include <cstdlib>//C++
strtol(): (某进制转换方法)
static void solve(const char a[], const char b[], const char c[]) { static char* end = new char;//废串,static 避免 stack overflow,new很有必要 for (int i = 2; i <= 16; i++) { if (strtol(a, &end, i)*strtol(b,&end,i) == strtol(c, &end, i) && not_found(a,i) && not_found(b,i) && not_found(c,i)) { cout << i; end = NULL;//赋值NULL return; } } cout << 0; end = NULL;//赋值NULL return; }
atoi():
int a = atoi("20");
其实我没有离线!有事请留言,一般在两三小时内回复!
其实我没有离线!有事请留言,一般在两三小时内回复!
+1完全看不懂
坚持是成功别名 只有唯一的我
你太厉害了!!!
我都看不懂
喜欢历史的,请关注我的签约专栏《历史掌故》。
算了,当时太弱了
map<T,T> 在取值方面会出现问题吧?