I want to ask the user for the name of a text file and then have the file read into a vector which I will then sort. My question is: How do I read the file through a user-given statement? For example, the user will type "words.txt" and that file will load. This is what I have so far
I'll help you out. Lets look it over. You wish to have a person input a name/string/w.e you want to call it, and then use that information to open a file corresponding with that.
Well think it over, just get the persons input first store it into a variable then create your ifstream object with the variable that the person inputted.
Hmm I think that should fix it. If I'm not mistaken it only accepts character constants... And we are giving it a string... I'm not quite sure how that works out.
That's as far as I know about c_str().
But I do understand that c_str() returns a pointer array of chars equivalent to the string given it(there's more to it though), which is why the constructor of ifstream can handle.
But what I have figured out is that data() works just as fine as c_str().
The thing about data() is that it returns a pointer array of characters equivalent to the string... Which the ifstream constructor can handle.