Dziwnie pobierasz dane. Lepszy sposób:
while (in >> wzorzec >> tekst)
Jeżeli słowa są tej samej długości to pętla powinna wykonać się przynajmniej raz:
int dt = tekst.length(); // -1 też było złe
int dw = wzorzec.length(); // btw czemu int, a nie std::size_t / std::string::size_type
bool ok = 0;
for (int i = 0; i < dt - dw + 1; i++)
Zadanie można wykonać krócej:
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::ifstream in("slowa.txt");
std::string word, pattern;
int counter = 0;
while (in >> pattern >> word)
{
if (word.find(pattern) != std::string::npos)
{
counter++;
}
}
std::cout << counter;
}