Hi every one I have the following problem I need to build a vector array from a file.
I managed to creat a vector by reading the file into a string buffer then saving it into this following vector.
vector<char> pattern(contents.begin(), contents.end());
But I have the following function that I need to pass the vector to.
void WuManber::Initialize( const vector<const char *> &patterns,
bool bCaseSensitive, bool bIncludeSpecialCharacters, bool bIncludeExtendedAscii )
how can I read from a file a passable vector to this function.
thank you for your help.
to elaborate more I need it to do the following
for ( size_t q = m; q >= B; --q )
{ // start loop -8-
unsigned int hash;
hash = m_lu[patterns[j][q - 2 - 1]].offset; // bring in offsets of X in pattern j
hash <<= m_nBitsInShift;
hash += m_lu[patterns[j][q - 1 - 1]].offset;
hash <<= m_nBitsInShift;
hash += m_lu[patterns[j][q - 1]].offset;
size_t shiftlen = m - q;
m_ShiftTable[ hash ] = min( m_ShiftTable[ hash ], shiftlen );
if ( 0 == shiftlen )
{ // start if -8-
m_PatternMapElement.ix = j;
m_PatternMapElement.PrefixHash = m_lu[patterns[j][0]].offset;
m_PatternMapElement.PrefixHash <<= m_nBitsInShift;
m_PatternMapElement.PrefixHash += m_lu[patterns[j][1]].offset;
m_vPatternMap[ hash ].push_back( m_PatternMapElement );
} // end if -8-
int main(int argc, char* argv[])
{
if (argc < 2) {
std::cout << "usage: " << argv[0] << " <filename>\n";
return 2;
}
ifstream fin(argv[1]);
if (fin) {
stringstream ss;
// this copies the entire contents of the file into the string stream
ss << fin.rdbuf();
// get the string out of the string stream
string contents = ss.str();
cout << contents;
// construct the vector from the string.
vector<char> pattern(contents.begin(), contents.end());
Initialize( &pattern);
cout << pattern.size();
}
else {
cout << "Couldn't open " << argv[1] << "\n";
return 1;
}
return 0;
}
The function is looking for a
vectorof C strings (that’s the most likely meaning ofconst char *inside a container namedpatterns.Here is how you can build one:
If you or your team designed this function, you may want to suggest changing the container type to a more C++ – ish
vector<string>.If you are reading your patterns from a file, you can populate your array as follows:
EDIT (in response to a comment)