我有一个函数void mainRoutine(string searchStrings, string fileBeingSearched, char K, char B);
我希望mainRoutine函数中的参数,searchStrings和fileBeingSearched是用户输入的文件的名称。(例如 - 我输入" b.txt",这是字符串searchStrings应该接受。)。
所以在我提示用户输入文件名后:
string userInput;
cout << "Please enter the string file to be searched: " << endl;
getline(cin, userInput);
ifstream filename(userInput.c_str());
while(filename.good()&&filename.peek()!=EOF)
{
cout << (char)filename.get();
}
cout << "\n";
string userInput2;
cout << "Please enter the file to be searched: " << endl;
getline(cin, userInput2);
ifstream fileToBeSearched(userInput.c_str());
while(fileToBeSearched.good()&&fileToBeSearched.peek()!=EOF){
cout << (char)fileToBeSearched.get();
}
cout << "\n";
如何连接它以便userInput是函数参数的字符串?
答案 0 :(得分:1)
mainRoutine(userInput, userInput2, K, B);
假设K和B是 char 类型