może tak działa ale na forum czytałem ze tak się nie robi
#include <iostream>
#include <sstream>
#include <bitset>
#include <iomanip>
#include <string>
#include <algorithm>
std::string binaryInt (int i) {
std::bitset<sizeof(i)*8> s(i);
std::stringstream ss;
ss<<s;
return ss.str();
}
std::string StartFromOne(std::string s) {
size_t p=s.find('1');
std::string binstr;
if(p!=s.npos) binstr=s.substr(p);
else binstr="";
return binstr;
}
void coutbodh (int i) {
std::bitset<sizeof(i)*8> s(i);
std::cout <<" bin i="<<s<<std::endl;
using std::oct;
using std::dec;
using std::hex;
std::cout <<oct<<" oct i="<< i;
std::cout <<dec<<"\n dec i="<< i;
std::cout <<hex<<"\n hex i="<< i;
std::cout <<'\n'<<std::string(30,'_')<< std::endl;
}
void ssistreambodh (int i,const std::ios::fmtflags & base) {
std::cout <<"dane i=";
std::stringstream ss;
ss.setf(base,std::ios::basefield);
ss<<i;
std::cout <<ss.str()<<'\n'<< std::endl;
}
using namespace std;
int main() {
int i; //tylko dodatnie
i=10;
ssistreambodh (i,ios::dec);
coutbodh (i);
i=0150;
ssistreambodh (i,ios::oct);
coutbodh (i);
i=0Xa5;
ssistreambodh (i,ios::hex);
coutbodh (i);
i=0b000010010010;
std::string sw=StartFromOne(binaryInt(i));
cout <<"dane i=0b"<<sw<< '\n'<<endl;
coutbodh (i);
return 0;
}