how to use user input for filename?

I am trying to have the user input a filename and then open that file? I cannot seem to figure it out. Is this anything close to what it is suppose to be? Have tried these various different approaches.

In main:

fileName = getFileName(fileName);
ifstream infile;
infile.open(fileName);


ifstream infile;
infile.open(getFileName(fileName));

ifstream infile(fileName);



function:

char getFileName(char){
char fileName;
cout << "Enter the name of the file you wish to use including extension: ";
cin >> fileName;
return fileName;

Any help would be greatly appreciated.
Change your getFileName to this:
1
2
3
4
5
6
string getFileName()
{
  string fname;
  cout << "Enter the name of the file you wish to use including extension: ";
  cin >> fname;
  return fname;


When you open you files do this:
ifstream infile(fileName.c_str());
Thanks a ton I have it working now =]
Topic archived. No new replies allowed.