i want to count the total number of the selected lines (hello world) in my program. My program is able to give the line number of the selected line but i want the total number of lines to be displayed.
Your loop is useless, it does only one iteration. If you think that amount of strings to search will grow, you can leave it, else replace it with its boby content.
Do you need to output number of found lines? In this case you did almost everyhing right, but placement of total increase is incorrect: you need to increment it if line matchs some other string, so you should put in the if statement body.
You want output after you processed your file, so you need to output total after while loop.
Also your while loop is incorrect. Do not loop on eof. It is almost always wrong. It does not stop when needed. You can see it in your output: your loop processes 6 lines out of 5
Correct approach is to loop on input operation: while(getline(file,data)) { ///...