Używam Linuxia i plik za nic nie chce mi się otworzyć. Znajduje się w tym samym folderze co program. Nie jest otwarty w innym programie. Podobno ta instrukcja:

ifstream ifs {filename};

automatycznie otwiera plik.

#include <iostream>
#include <fstream>

using namespace std;

bool print_lines_wf_word(const string &filename, const string &word) {
  ifstream ifs {filename};
  if (!ifs.good()) {
    cout << "couldnt open" << endl;
    return false;
  }
  else {
    string line;
    while (getline(ifs, line)) {
      if (line.find(word) != string::npos)
        cout << line << endl;
    }
    ifs.close();
    return true;
  }
}

int main() {
  string word;
  cout << "word:";
  cin >> word;
  const string filename = "./wiersz.txt";
  print_lines_wf_word(filename, word);
  return 0;
}

Edit:Okazało się, że ./wiersz.txt nie odnosi się do folderu w którym jest plik, ale do tego w którym jestem w konsoli.