Hello, I have a text file where in each line is 3 words and 2 int type numbers. I'm doing search by word and I want to print out to the screen the whole line where that word was found (the words is repeated in some lines). My search looks like this:
How to print line(s) where I found that word?Code:#include<iostream>
#include<string>
#include<fstream>
#include<stdlib.h>
#include <vector>
using namespace std;
int main(){
vector <string> words;
string str, paieska;
ifstream fin("duom.txt");
while (fin >> str)
{ words.push_back(str); }
cout<<"Iveskite paieskos zodi"<<endl;
cin>>paieska;
for (int i = 0; i < words.size(); ++i){
if (paieska==words.at(i)){
cout<<"Rasta: "<<words.at(i)<<endl<<i<<endl;}}
fin.close();
return 0;
system("pause"); }