Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

input File name?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hi,
I am having trouble with something I think you techies can
help me easily.
C++ will prompt the user for the name of the input file to open. Do I do it like this?

ifstream inputFile("Something");
cout<<&quot;Enter name of Input file you want C++ to open: &quot;;
cin>>inputFile;

ok, how do I cin the name of the file?I hope you can understand my question.thnkx in advance.
 
#include <iostream>
#include <fstream>

using namespace std;

#define MAX_FILE_NAME 20

int main()
{
char sNameOfFile[MAX_FILE_NAME];
ifstream inFile;

cout << &quot;Enter the file name: &quot;;
cin.getline( sNameOfFile,MAX_FILE_NAME );

inFile.open( sNameOfFile );

if ( inFile.fail() )
cout << sNameOfFile
<< &quot; could NOT be opened.&quot;
<< endl;
else
cout << sNameOfFile
<< &quot; was opened successfully.&quot;
<< endl;

return 0;

} Mike L.G.
mlg400@blazemail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top