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!

accepting input filename interactively and using it in C++

Status
Not open for further replies.

catalina

Programmer
Feb 7, 2002
3
US
I am writing a program where user enters input filename interactively when program runs and my program has to take that user entered string as file name and get data from this file. I know how to use constant file name, but not variable. Please help. Thanks.
 
Something like this?
Code:
char buf[512];
cout<<&quot;Input file name&quot;;
cin>>buf;
fstream stream;
stream.open(buf,ios::in|ios::nocreate);
if(!stream){
     cerr<<&quot;error: could not open file &quot;<<buf;
     exit(1);
}

//then read from the file here just
//as you would read from cin
Is something like this what you were looking for? I'm assuming that this is from the command prompt. Am I correct in this assumption? MYenigmaSELF:-9
myenigmaself@yahoo.com
&quot;If debugging is the process of removing bugs, then programming must be the process of putting them in.&quot; --Dykstra
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top