What is the "something" above?Code:ifstream file_input("myinputfile.txt"); cout << file_input.something; // prints "myinputfile.txt"
What is the "something" above?Code:ifstream file_input("myinputfile.txt"); cout << file_input.something; // prints "myinputfile.txt"
Like this?
Or what is your question? I don't think ifstream stores the name of the file if that's what you mean. If you opened the file, the name was available to you - why can't you use that?Code:#include <iostream> #include <string> struct ifstream { std::string something; ifstream(const std::string& sth): something(sth) {} }; using std::cout; int main(){ ifstream file_input("myinputfile.txt"); cout << file_input.something; // prints "myinputfile.txt" }
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
If it is a command line argument then it is stored in a variable? Why can't you use that?
Code:string name = "somefile.txt"; ifstream fin(name.c_str()); if (!fin) { cout << "Couldn't open " << name; }
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.