I'm very curious why I'm getting a malloc
error here:
ifstream infile (filename);
unsigned count=0; // TODO testing only
do {
string s;
infile >> s; <-- fails here at word 858
} while( ++count < 10000 );
error:
malloc.c:3695: _int_malloc: Assertion `(unsigned long) (size) >= (unsigned long) (nb)' failed.
Aborted
This code is reading in newline-delimited words. It fails when it hits the 858th word, which is achromobacterieae. At 17, it's the first word longer than 15 characters, but other than that I can't see any sign of the problem.
EDIT:
The object containing this code uses boost's bimap. If I change the Bimap
typedef
from this
typedef boost::bimap< boost::bimaps::unordered_set_of<unsigned>, boost::bimaps::unordered_set_of<std::string> > Bimap;
to this
typedef boost::bimap< unsigned, string > Bimap;
the error disappears.
At the risk of being verbose, here's the complete header file:
#include<iostream>
#include<fstream>
#include<vector>
#include<unordered_map>
#include<boost/bimap.hpp>
#include<boost/bimap/unordered_set_of.hpp>
#include"board.h"
using namespace std;
typedef unordered_map<unsigned, vector<unsigned> > Referencemap;
// typedef boost::bimap< boost::bimaps::unordered_set_of<unsigned>, boost::bimaps::unordered_set_of<string> > Bimap;
typedef boost::bimap<unsigned, string> Bimap;
class Words {
public:
Referencemap referencemap;
Bimap reference;
public:
Words(char* filename, Board* b);
private:
void addToStringmap(const string& s);
};
The variables referencemap
and reference
are only declared, never used.
Aucun commentaire:
Enregistrer un commentaire