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.
Printable View
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
thanks alot for the help