Prompt for User Input Function?

I'm writing a function that prompt for the user string input and output file and I want to use the input in another function.
Here's the function:
1
2
3
4
5
6
7
8
string getInput(string name)
{
cout << "Enter input file name : ";
cin >> fname;
cout << endl;

cout << "Enter output file name: ";
cin >> fname;


I want to call and use this function in anther function, not the main program.
1
2
3
4
5
6
void CheckFile( ofstream &outF)
ifstream input;
ofstream output

// here i want to open the input file. like: input.open(inputfile.c_str() )
// here i want to open the output file. like: output.open(outputfile.c_str() ) 
You're looking for pass-by-reference.

1
2
3
4
5
6
7
8
9
void getInput(string& inputFile, string& outputFile)
{
cout << "Enter input file name : ";
cin >> inputFile;
cout << endl;

cout << "Enter output file name: ";
cin >> outputFile;
}



1
2
3
4
5
6
7
8
9
void CheckFile(string& inputFile, string& outputFile)
{
ifstream input;
ofstream output

input.open(inputfile.c_str() )
output.open(outputfile.c_str() )
// more code, presumably
}


Last edited on
Topic archived. No new replies allowed.