?
Solved

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

Posted on 2001-07-24
9
Medium Priority
?
592 Views
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>?

_ryan
0
Comment
Question by:tetsuo
[X]
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
9 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 6315829
Are you using the proper namespace?

Can you show your code?
0
 
LVL 30

Expert Comment

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

Author Comment

by:tetsuo
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?

_ryan

i'll post code shortly, i cannot get to it right now..
0
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

by:tetsuo
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  {

    public:

        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);

    private:

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

};

class LZEncoder {

    public:

        LZEncoder();

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

    private:

        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()) {
            currentWord.append(messageVector[messageIndex]);
            messageIndex++;

            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]<<" ";
    }

    //cout<<"\nDONE!\n";
}

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

    //cout<<"\nDONE!\n";
}

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

    //cout<<"\nDONE!\n";
}

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";
        exit(1);
    }

    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++) {
        in.read(c, 1);
        b = c[0];
        bs = b;
        cout<<bs<<'\n';
        temp = bs.to_string();
        mess.append(temp);
    }

    cout<<"\nmess is: "<<mess<<"\n";
    in.close();
}


istream & operator>>(istream & is, string & st) {
    char temp;
    is.get(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();
}




LZEncoder::LZEncoder()
{

}

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";
        x++;
    }


    cout<<"\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
                                           //consistent.
    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);
                break;
            }
        }
        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]<<") ";
        i++;
    }
    cout<<'\n';
}


/* 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

_ryan

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

Expert Comment

by:Axter
ID: 6316933
>>using std::to_string;

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

Author Comment

by:tetsuo
ID: 6318667
0
 

Author Comment

by:tetsuo
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
0
 
LVL 11

Expert Comment

by:griessh
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: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 5

Accepted Solution

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

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

762 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