How do you make a c++ program search for a string? -
how make c++ program search string?
i'm new programming language c++.
is there way program string of .txt file , if program found it?
first open ifstream open file check string:
#include <iostream> #include <fstream> #include <string> using namespace std; int main () { string line; ifstream myfile ("example.txt"); if (myfile.is_open()) { while ( getline (myfile,line) ) { if(line.find("the string find") != string::npos) { //line found, } } myfile.close(); } else cout << "unable open file"; return 0; }
Comments
Post a Comment