Hello, I am new to C++ and very lost. I have attempted this program but my output displays file was unable to open. I am not sure I am even on the right track. Here is my project:
Write a program that reads strings from a file into a vector. Ask a user to enter a string to be found. The program should display the index in the vector where that string was foud and the string, or display a messag telling teh user that the string was not found.
Any help would be appreciated!!
Here's what I have so far:
I don't think so because I found a similar program in the book that i used as a guide. Do I have to create the text file before I begin? I thought I could create and write it at once. I am so lost!
Sorry, didn't read it well enough:p I thought you were trying to read an already existing file. Does it display the very same error-message that you created, the "File failed to open"?
If you want to write to a file, you need to use ofstream, not ifstream like you are doing here. Right now, it's trying to read a file that's not there, which is why it's giving you the error.