bitset::to_string()  won't compile with g++

Posted on 2001-07-24
Last Modified: 2012-08-13
i'm in linux and trying to use the bitset::to_string() function to convert a bitset to a string.  but g++ keeps giving me these errors saying that it doesn't recognize the function.  is there anything else i need to include besides <bitset>?

Question by:tetsuo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 30

Expert Comment

ID: 6315829
Are you using the proper namespace?

Can you show your code?
LVL 30

Expert Comment

ID: 6315831
<bitset> should be the only include you need.

Author Comment

ID: 6315958
i tried this:

#include <bitset>

using std::to_string;

but it didn't help the problem.  what is the proper namespace i should use?


i'll post code shortly, i cannot get to it right now..
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 6316348
here is the code:

 * lz.h - header file for all lz components

#include <cmath>

#include <vector>

using std::size;
using std::begin;
using std::end;

#include <iostream>

using std::cout;
using std::cin;
using std::cerr;

#include <fstream>

using std::ifstream;
using std::good;
using std::read;
using std::write;

#include <string>

using std::string;
using std::append;

#include <bitset>

using std::to_string;

#include <sstream>

using std::sstream;
using std::itostring;

class LZParser  {


        void parse();  //performs LZ parsing on messageVector
        void printMessageVector();   //what do you think??
        void printBlockVector();     //ditto
        void printAlphabet();        //ditto

        void getBlockVector(vector<string> & b);

        bool checkFor(string word);  //checks for previous occurrence
                                     //of currentWord in blockVector

        void readFile(string filename);   //read in the data file
                                          //and set the alphabet.

        void readBinary (string filename);   //read in the data file
        friend istream & operator>>(istream & is, string & st);


        vector<string> alphabet;
        vector<string> messageVector;
        vector<string> blockVector;


class LZEncoder {



        void lzEncode();
        void createPairs(vector<string> &blocks);
        void printPairs();


        vector<string> pairs;


 * lzparser.cxx - impelentation of a lzparser

#include "lz.h"

LZParser::LZParser ()


void LZParser::parse()

    string currentWord = "";
    int messageIndex = 0;
    bool done = false;

    currentWord = messageVector[0]; //first block is X1
    cout<<"first word is:::: "<<currentWord<<"\n";
//    messageIndex++;

    while (messageIndex < messageVector.size()) {
        done = false;
        currentWord = "";

        //this inner loop constructs the next shortest prefix not
        //already contained in the block vector.

        while (!done && messageIndex < messageVector.size()) {

            if (!checkFor(currentWord)) {
                cout << "inserting *" <<currentWord<< "* into blockVector\n";
                blockVector.insert(blockVector.end(), currentWord);
                done = true;
            //if the word is already contained but we are at the end,
            //just add the word to blockVector, (Edited by Computer101) it.
            else if (messageIndex >= messageVector.size() - 1) {
                blockVector.insert(blockVector.end(), currentWord);

void LZParser::getBlockVector(vector<string> & b)
    b = blockVector;

//check for this word in blockVector
bool LZParser::checkFor(string word)
    string w = "";
    int i;

    if (blockVector.size() <= 0) {
        return false;

    for (i = 0; i < blockVector.size(); i++ ) {
        if (blockVector[i] == word) {
            return true;
    return false;


void LZParser::printMessageVector()

    for (int i = 0; i < messageVector.size(); i++) {
        cout<<messageVector[i]<<" ";


void LZParser::printBlockVector()
    for (int i = 0; i < blockVector.size(); i++) {
        cout<<blockVector[i]<<" ";


void LZParser::printAlphabet()
    for (int i = 0; i < alphabet.size(); i++) {
        cout<<alphabet[i]<<" ";


void LZParser::readFile(string filename)
    bool contained = false;
    int k;

    ifstream inFile (filename.c_str(), ios::in);

    if (! inFile.good() ) {
        cerr << "Input file could not be opened!\n";

    string str;

    while (inFile>>str) {
        contained = false;
        messageVector.insert(messageVector.end(), str);
        for (k = 0; k < alphabet.size(); k++) {
            if (str == alphabet[k]) {
                contained = true;

        if (!contained) {
            alphabet.insert(alphabet.end(), str);

    //cout<<"Finished constructing message vector.\n";

void LZParser::readBinary (string filename)

    ifstream in (filename.c_str(), ios::in | ios::binary);

    string mess = "";
    string temp = "";
    char c[1];
    unsigned long b;
    bitset<8> bs;

    for (int i = 0; i < 13; i++) {, 1);
        b = c[0];
        bs = b;
        temp = bs.to_string();

    cout<<"\nmess is: "<<mess<<"\n";

istream & operator>>(istream & is, string & st) {
    char temp;
    if (is)
        st = temp;
    return is;

#include "lz.h"

std::string itostring(int i)
  std::ostringstream os; // Note no length restrictions on the data.
  os << i;
  return os.str();



void LZEncoder::lzEncode()


void LZEncoder::createPairs(vector<string> &blocks)
    cout<<"block vector output without iteration..\n";
    cout<<"now creating pairs...\nreceiving blockVector from lzparser...\n";
    for (int x = 0; x < blocks.size()-1; x++) {
        cout<<"blocks["<<x+1<<"] = "<<blocks[x]<<"\n";
    int x = 0;
    while (x < blocks.size()) {
        cout<<"blocks["<<x+1<<"] = "<<blocks[x]<<"\n";


    int i, k;

    string blockNum = "0", concat = "";
    string currentBlock = "";

    //first pair
    pairs.insert(pairs.end(), blockNum);   //i'm following ali's notes here.
                                           //i don't think the ordering
                                           //matters, as long as it's
    pairs.insert(pairs.end(), blocks[0]);

    //parse each variable length block currentBlock and try to
    //find a previous block of length currentBlock.length()-1 that
    //matches the subblock of the same size of the currentBlock.
    //if found, that is the block number of the current pair,
    //and concatenation is currentBlock[currentBlock.length()-1],
    //(the last character of the current block)

    for (i = 1; i < blocks.size(); i++) {
        currentBlock = blocks[i];  //get current block
        concat = currentBlock[currentBlock.length()-1];  //get last char

        currentBlock.erase(currentBlock.length()-1);  //erase last char to
                                                      //create sub block.
        cout<<"\nblock is:"<<blocks[i]<<"\n";
        cout<<"concat is: "<<concat<<"\nsearching for "<<currentBlock<<"\n";

        for (k = 0; k < i; k++) {
            if (blocks[k] == currentBlock) {
                cout<<"FOUND: "<<blocks[k]<<"\n";
                blockNum = itostring(k+1);
        cout<<"inserting blockNum: "<<blockNum<<"\n";
        cout<<"inserting concat: "<<concat<<"\n";

        pairs.insert(pairs.end(), blockNum);
        pairs.insert(pairs.end(), concat);



void LZEncoder::printPairs()
    for (int i = 0; i < pairs.size(); i++) {
        cout<<"("<<pairs[i]<<','<<pairs[i+1]<<") ";

/* end of code */

i'm sorry if the format is all screwy, this text box is not so big.  so am i not including something?  i've tried looking up standard template library references and i don't know what i'm doing wrong.  any help is appreciated, i will make sure that ALL who help will get the acknowledgement they deserve!  thanx


p.s.  i will clarify any of my code upon request  ;)
LVL 30

Expert Comment

ID: 6316933
>>using std::to_string;

That is not the right namespace.
using std::bitset;//Correct

Author Comment

ID: 6318667

Author Comment

ID: 6318829
that didn't work.  here is the error i get:

lzparser.cxx: In method `void LZParser::readBinary (basic_string<char,
string_char_traits<char>, __default_alloc_template<true, 0> >)':
lzparser.cxx:150: no matching function for call to `bitset<8, long
unsigned int>::to_string ()'
make: *** [lzparser.o] Error 1
LVL 11

Expert Comment

ID: 6833180
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points and PAQ at zero points since nobody had a satisfying answer for you.

The link to the Community Support area is:


Accepted Solution

Netminder earned 0 total points
ID: 6853166
Per recommendation points refunded and question closed.

Community Support Moderator
Experts Exchange

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 151
computer science syllabus 3 114
I could not build boost code, 10 114
Printing the elements of a set declared inside a map in C++. 3 66
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question