c++解码,需要将前端传过来的转换成中文

问题遇到的现象和发生背景

前端传过来的中文参数是%3D%E9%98%BF%E8%90%A8%E8%BE%BE%26,需要将这个参数转换为中文

问题相关代码,请勿粘贴截图
#include "stdafx.h"
#include <iostream> 
#include < codecvt>
#include <locale>

std::string unicodeToString(const std::string &str) {
std::string u8str ;
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> converter; 
for (size_t i = 0; i < str.length(); ) {
char32_t uhan = strtol(str.substr(i,4).c_str(), nullptr, 16);
u8str += converter.to_bytes (uhan);
i+=4;
}
return u8str;
}
int main() {
std::cout << unicodeToString( "4F 60597D554A" ) << std::endl ; 
return 0;
}


运行结果及报错内容

img

我的解答思路和尝试过的方法

在网上试了好多方法,要么是代码报错,要么就是解析出来的是乱码

我想要达到的结果

#include <stdio.h>
#include <string.h>
#include <windows.h>
int main() {
    char s[]="%3D%E9%98%BF%E8%90%A8%E8%BE%BE%26";
    char msg[256];
    char b[256];
    WCHAR wstr[256];
    int i,L;

    i=0;
    while (1) {
        if (1!=sscanf(s+i*3,"%%%02X",&L)) break;
        msg[i]=(char)L;
        i++;
        if (i>=256-1) break;
    }
    msg[i]=0;
    L=strlen(msg);
    i=MultiByteToWideChar(CP_UTF8,0,msg,L,wstr,256);
    wstr[i] = 0;
    i=WideCharToMultiByte(CP_OEMCP,WC_COMPOSITECHECK,wstr,i,b,256,0,0);
    b[i]=0;
    printf("[%s]\n",b);//[=阿萨达&]
    return 0;
}


试试这个
https://blog.csdn.net/ningxiaowei2013/article/details/52594330

decodeURIComponent('%3D%E9%98%BF%E8%90%A8%E8%BE%BE%26')
'=阿萨达&'

c++ 应该也有现在库吧 decodeURI 类似的搜索一下

楼上的C实现已经相当高效了,我续个C++版本的
https://blog.csdn.net/m0_54206076/article/details/125570947