小编nur*_*tul的帖子

如何在Python 3中使用字符串类型对变量进行base64编码/解码?

它给出了一个错误,即编码的行必须是字节而不是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编码/解码字典.

python base64 dictionary encode decode

5
推荐指数
1
解决办法
1万
查看次数

C - 在数组中使用malloc()存储指针,之后不能释放它们

我想存储pointers已经使用被分配malloc()arrayfree毕竟他们.然而,即使该程序没有抱怨它不起作用.下面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)

c arrays malloc pointers memory-management

2
推荐指数
1
解决办法
391
查看次数

itoa()的C++标准替代,将int转换为基数10 char*

将整数转换为基数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)

c++ windows string int itoa

0
推荐指数
1
解决办法
2601
查看次数

标签 统计

arrays ×1

base64 ×1

c ×1

c++ ×1

decode ×1

dictionary ×1

encode ×1

int ×1

itoa ×1

malloc ×1

memory-management ×1

pointers ×1

python ×1

string ×1

windows ×1