Untitled
unknown
c_cpp
a year ago
684 B
8
Indexable
#include <fstream>
#include <iostream>
#include <string>
int main()
{
std::string filename = "example";
std::ifstream file( filename + ".txt" );
if( file.good() )
{
std::string keyword;
std::cout << "Podaj wyraz do wyszukania: ";
std::cin >> keyword;
std::string line;
while( std::getline( file, line ) )
{
if( line.find( keyword ) != std::string::npos )
{
std::cout << line << '\n';
}
}
}
else
{
std::cerr << "Nie mozna otworzyc pliku: " << filename << '\n';
}
file.close();
return 0;
}
Editor is loading...
Leave a Comment