Still having trouble actually showing the output to the screen.
Change the Ostream to cout then.
Code:
Ostream << counter << " occurences of the word: " << userDefinedSearch;
Outputs to the file s_rlpruett.txt like I thought you said you wanted?
Code:
cout << counter << " occurences of the word: " << userDefinedSearch;
Will output to the screen.
When you run my code, and for the file I created when you open the s_rlpruett.txt you get the following results:
Code:
1) occurence is on line: 1
2) occurence is on line: 5
3) occurence is on line: 20
4) occurence is on line: 32
5) occurence is on line: 32
..
..
34) occurence is on line: 145
34 occurences of the word: semper
Not familar with the peek command and a few others. Is there another way of implementing those
Yes, but the standard commands are there for a reason. Very usefull!
For strings:
http://www.cppreference.com/cppstring/
For input and output (cin, cout ect):
http://www.cppreference.com/cppio/
Alternatively though. Every time you call getline you know it is moving to a new line. So when you use get line you can dump the char and the peek (again my code was just for words not phrases) and increment the line counter by one. That is, increment the line character by one every while loop, because you know if it is going around again it is on a new line.
Not sure of the getline usage also
You have it right for the user to input.
Code:
getline(input_Stream,string_it_goes_in)
So in the while loop change the
Code:
Istream >> stringLine;
Which is just line cin >> stringLine (but from the file and not the user) to
Code:
getline(Istream,stringLine);
Right now I get an infinite Loop of whatever Word I enter.
Of course.
Explain to your self in words this code you have:
Code:
while (Istream != 0)
What do you think that does?
But then in your while loop you will have to search the string:
http://www.cppreference.com/cppstring/find.html
for the word or phrase the user entered and then increment the counter by one, ect.
*edit*
Go back through my code and make sure you understand what is going on (you can ignore the peek since you will not need it when you use getline).
To create the program you want (search for phrase) it only requires dumping the peek, change the cin>> to the getline (and the filestream >> to the getline) and use that find link and you are done). We are talking deleting the peek stuff, deleteing the if (check == '\n') and changing the if statement and you are done.