| | |
get user input for filename to open
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I'm going to give you the code.
You're going to study it
This doesn't actully do anything with the file, but it opens the file that the user requests.
I havn't tested it, so you might have to fix it up. Have fun!
You're going to study it

C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main( ) { cout << "Please enter a file name: \n"; string name; cin >> name; ifstream ist(name.c_str( )); //c style strings are required by some system interfaces if(!ist) cerr << "Can't open file!\n"; // if the file failed to open cin.clear(); cin.get(); }
This doesn't actully do anything with the file, but it opens the file that the user requests.
I havn't tested it, so you might have to fix it up. Have fun!
Last edited by tomtetlaw; Jul 21st, 2009 at 8:30 am.
...
![]() |
Similar Threads
- Validating user input against text file (Python)
- get user input for file name to open? (C++)
- Help Newbie on User input verification Loop (Python)
- user input stops loop (C++)
- please help pasting user input onto ofstream open() (C++)
- am i using fgets correctly? (Cprog) (C)
- Need Help With Error Checking User Input (C)
- filtering bad user input (Java)
Other Threads in the C++ Forum
- Previous Thread: Push-button basic question
- Next Thread: strstr implementation from scratch
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project proxy python random read recursion recursive reference rpg simple sorting string strings template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






