Reading A Users Input?
I'm trying to read a users input like so : bf "pattern" filename, Where
'bf' determines an algorithm to run, pattern is the type of string we are
looking for inside the filename, and filename is what file to open.
My question is how to I read the pattern such that I can read every
character in between the two quotes? Also how do I accurately read the
filename?
int main(){
string text, line, pattern;
getline(cin, line);
if( line == "mp"){
'Run Morris Pratt Algo'
}else if( line == "bf"){
'Run Brute Force'
}
return 0;
}
code to read filename:
int findFile(){
string fname, line;
ifstream ifs;
int i;
//string pattern = substring(3,5);
while(getline(cin, fname)){
ifs.open(fname.c_str());
if( ifs.fail()){
cerr << "ERROR: Failed to open file " << fname << endl;
ifs.clear();
} else {
i = 0;
while(getline(ifs, line)){
cout << " Line" << i++ << " : " << line << endl;
ifs.close();
}
cout << "---- Enter another file name : ";
}
}
}
No comments:
Post a Comment