I know we're not supposed to ask for complete answers on this board, but I'm on vacation, and I'm trying to do a question, and I'm completely stumped:
Here's the question (please just help me in the right direction):
Code:Please write a program that does the following: 1. Requests a file name from the user. 2. Opens the file, quitting if the file is not valid. 3. Asks the user for the string. 4. Reads in the file, line by line, and searches in each line to see if the string the user typed in occurs in the line. ******** I'm not sure how to read in line by line??? I only know how to do this with istream_iterators************ 5. If the string is in the line, the whole line is written out to a file called "occs.txt", along with the number that the line occupied in the original file. ********** I'm not sure how to cout the line number of the file either ********** Example: if there is a files called test.txt which contains: hello there why do birds suddenly there appear? And the user request that file, and searches for the string "there", then occs .txt should read: Line 1: hello there Line 2: suddenly there note: solve this problem using the c++ standard libraries, not the c equivalents. So use ifstream, and ofstream for the i/o, and string of course. A careful search through string in the STL primer(book) may provide extra clues to simplify your task
I'm truely stumped on this one. If anyone could please lead me in the right direction, I'd appreciate it.