Dec 2, 2015 at 12:13am UTC
cout the name of he inFile
Do you mean like outputing the phrase "test.txt"?
Just in case you're wondering. Neither the istream or ostream classes save the name of your filename. So you
can not do anything like this.
1 2
ifstream fin("test.txt" );
cout << fin.getFileName(); // This does not exist.
Last edited on Dec 2, 2015 at 12:22am UTC
Dec 2, 2015 at 12:16am UTC
yes..
so, if someone changes the inFile name, the cout will still output the name of the inFile
Dec 2, 2015 at 12:32am UTC
You'll have to save the name of the textFile in a another variable.
I'm not going to lie. This can be kind of tricky. So you need to be very specific with me. I'll explain to you why in a moment.
1.) Is "text.txt" the only file name you want to use? (AKA is it going to be constant)
2.) How is "test.txt" set? Does the user input the file name, or is it hardcoded in (I.E. inFile = "text.txt" vs cin >> inFile)
EDIT:
Why does this matter? Because the operators "=" and ">>" will not work unless the conditions are correct.
Last edited on Dec 2, 2015 at 12:36am UTC
Dec 2, 2015 at 1:25am UTC
1. Yes
2. It is hard coded by whoever I give the program to... not cin
I just wanted to add another feature to the program.
It's really not important... just pretty.
Dec 2, 2015 at 3:34am UTC
That's not too bad
1 2
char * inFile = "text.txt" ;
ifstream(inFile);
I was actually probably a little panicky. I had some nightmares with char arrays back in my day.
Last edited on Dec 2, 2015 at 3:35am UTC