它给出了一个错误,即编码的行必须是字节而不是str/dict
我知道在文本解决之前添加"b"并打印编码的东西.
import base64
s = base64.b64encode(b'12345')
print(s)
>>b'MTIzNDU='
Run Code Online (Sandbox Code Playgroud)
但是我如何编码变量呢?如
import base64
s = "12345"
s2 = base64.b64encode(s)
print(s2)
Run Code Online (Sandbox Code Playgroud)
添加和不添加b会给我一个错误.我不明白
我也试图用base64编码/解码字典.
我想存储pointers已经使用被分配malloc()在array再free毕竟他们.然而,即使该程序没有抱怨它不起作用.下面cleanMemManager()实际上free没有内存,因为在main()char*中测试时pointer没有NULL,它将打印???.
码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void **ptrList = NULL;
void tfree(void** ptr)
{
free(*ptr);
*ptr = NULL;
}
void* talloc(int size)
{
void* ptr = malloc(size);
ptrList[0] = ptr; ///No clue if this actually does what I think it does
return ptrList[0];
}
void initMemManager()
{
ptrList = (void**)malloc(sizeof(void**) * 3);
memset(ptrList, 0, sizeof(void**) * 3);
} …Run Code Online (Sandbox Code Playgroud) 将整数转换为基数10 char*
std::itoa(ConCounter, ID, 10);
Run Code Online (Sandbox Code Playgroud)
ConCounter是一个整数,ID是char*,10是基数
它说iota不是std的成员,没有std它没有声明.我知道这是一个非标准的功能,但我包含了它的所有库,它仍然没有看到它.
有什么方法可以做到这一点?任何快速的衬垫?我试过以下几点;
std::to_string //it's not declared for me when using mingw, it doesn't exist.
snprintf/sprintf //should work but it gives me the "invalid conversion from 'int' to 'char *'" error
std::stoi //has same problem as iota
Run Code Online (Sandbox Code Playgroud)