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.
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
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
thanks alot for the help