【发布时间】:2012-02-24 16:44:15
【问题描述】:
大家好,我有以下问题,我需要从文件构建一个向量数组。 我设法通过将文件读入字符串缓冲区然后将其保存到以下向量中来创建向量。
vector<char> pattern(contents.begin(), contents.end());
但是我需要将向量传递给以下函数。
void WuManber::Initialize( const vector<const char *> &patterns,
bool bCaseSensitive, bool bIncludeSpecialCharacters, bool bIncludeExtendedAscii )
我怎样才能从文件中读取一个可传递的向量给这个函数。 谢谢你的帮助。
要详细说明我需要它来执行以下操作
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;
}
【问题讨论】:
-
你想把什么向量传递给那个函数?它需要一个指针的向量。
-
你的文件内容和patterns参数有什么关系?文件的每一行都应该是一个模式吗?
-
是的,文件中的每一行都是一个模式
-
我需要它来执行以下操作
标签: c++ reference vector chat constants