hey,
I am working on a program in which i have to ask the user for a file name and then check for errors and read data from that file. I'm not sure how to do this. if I cin the file name as a string how do i use it?
any help is appreciated.
This is a discussion on File INPUT within the C++ Programming forums, part of the General Programming Boards category; hey, I am working on a program in which i have to ask the user for a file name and ...
hey,
I am working on a program in which i have to ask the user for a file name and then check for errors and read data from that file. I'm not sure how to do this. if I cin the file name as a string how do i use it?
any help is appreciated.
Code:#include <string> #include <fstream> #include <iostream> ... std::string str; std::cout << "Enter filename: "; // Prompt for filename std::cin >> str; // Get filename std::ifstream input(str.c_str()); // Open file
I used to be an adventurer like you... then I took an arrow to the knee.
thanks alot for the help