User Tools

Site Tools


development:cpp:char2string

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
        badgechars[1]=72;
 
        std::string badge(reinterpret_cast<const char*>(badgechars),2);
        //or
        badge += std::string(badgechars, badgechars + 2);
        //or
        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