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;
development/cpp/char2string.txt · Last modified: 2017/12/06 10:28 by tplecko