【发布时间】:2017-01-05 19:39:01
【问题描述】:
我正在尝试实现 Boyer Moore(坏字符启发式)算法,但我想使用动态数组。谁能帮我解决这个问题?这是我的源代码。
**/* Program for Bad Character Heuristic of Boyer Moore String Matching Algorithm */
# include <limits.h>
# include <string.h>
# include <stdio.h>
# define NO_OF_CHARS 256
/* Driver program to test above funtion */
int main()
{
char txt[];
char pat[];
ifstream myfile;
string filename;
cout<<"input file"<<endl;
getline(cin, filename);
myfile.open(filename.c_str());
if(myfile.is_open()){
cout<<"file not found"<<endl;
while(getline(myfile, txt))
{
cout<<txt<<endl;
}
cout<<"pls input pattern"<<endl;
cin.getline(pat[]);
search(txt, pat);
myfile.close();
}
else cout<<"file not found"<<endl:
return 0;
}**
【问题讨论】:
-
char txt[];-- 这不是有效的 C++。 -
我的意思是我的源代码中缺少的部分:
-
那么,问题是什么?
-
除非我想使用动态数组。 --
std::vector<char> -
我的问题是如何在这段代码中实现一个动态数组?我从哪里开始?