How to implement grep in C++
<p>I want to implement grep for a Shell I'm doing in Windows (just for learning purpose).<br>
I know that grep has the following syntax:</p>

<pre><code>grep pattern files
</code></pre>

<p>So I can make a function like:</p>

<pre><code>int grep(string stringToMatch, string fileName) // just one file
{
   // search file for stringToMatch
   // print line containing stringToMatch
}
</code></pre>

<p>My confusion is, how does grep supposed to work when I use a pipe like this: </p>

<pre><code>ls | grep someword
</code></pre>

<p>I implemented "ls" to put all the output in a vector and return that, so I guess then my grep should search the vector for the results. So how should the correct grep function look ?  Do I need 2 grep functions ?</p>

<p>Thanks in advance.</p>
