So basically I want to find in my text file "NAPIS.txt" every line which has 2 letter "A" in it and then append number of these lines and lines themselves to new text file "wynika.txt". For some reason these lines append multiple times and there is too much of them. here is code:
#include <iostream>
#include<vector>
#include<fstream>
using namespace std;
vector <string> t;
int main()
{
ifstream plikwe("NAPIS.txt");
ofstream pliwky_a("wynika.txt");
ofstream pliwky_b("wynikb.txt");
string temp;
int licz=0;
int licznik=0;
while(!plikwe.eof())
{
plikwe>>temp;
t.push_back(temp);
}
for(int i=0;i<t.size()-1;i++)
{
cout<<t[i]<<endl;
}
for(int i=0;i<t.size()-1;i++)
{
licz=0;
for(int j=0;j<t[i].size();j++)
{
if(t[i].at(j)=='A')
{
licz++;
}
if(licz==2)
{
licznik++;
pliwky_a<<t[i]<<endl;
}
}
}
pliwky_a<<licznik<<endl;
cout<<licznik<<endl;
return 0;
}