Untitled

mail@pastecode.io avatar
unknown
c_cpp
23 days ago
597 B
1
Indexable
Never
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
	ifstream inputFile("wiersz.txt");

	if (!inputFile.is_open())
	{
		cerr << "Nie mozna otworzyc pliku dane.txt!" << endl;
		return -1;
	}
	else
	{
		string word;

		cout << "Podaj slowo do wyszukania: ";
		getline(cin, word);

		cout << "\n\nWiersze tekstu ze slowem " << word << ":\n";

		string line;
		while (getline(inputFile, line))
		{
			if (line.find(word) != std::string::npos)
			{
				cout << line << endl;
			}
		}

		inputFile.close();
	}

	return 0;
}
Leave a Comment