Eureka Moment Wiki

One eureka moment at the time

User Tools

Site Tools


C++ Converting unsigned char array to std::string

#include <stdio.h>
#include <iostream>
#include <fstream>
int  main()
        std::string badge = "/badges/";
        unsigned char badgechars[12];
        badgechars[0]=64; //demo
        std::string badge(reinterpret_cast<const char*>(badgechars),2);
        badge += std::string(badgechars, badgechars + 2);
        badge.append(1, badgechars[0]);
        badge.append(1, badgechars[1]);
        std::cout << "Searching for " << badge << std::endl;
        return 0;


Enter your comment:
F K F​ L M
development/cpp/char2string.txt · Last modified: 2019/10/31 09:04 (external edit)