1. Next time use code tag with the language specifier for code snippets:
[code=cplusplus]
your code
[/code]
2. You accumulate all input file contents line by line in the stringstream sstr variable. Insert cout << sstr.str() << endl; statement after sstr << x; and try this on a small input file. Of course, it's not a desired effect, it's an error. You must replace previous sstr contents by a next line:
sstr.str(x);
In actual fact no need in stringstream at all. Use find member function to detect substrung s in input line x. Also change main loop condition:
while (getline(ifle,x)) { // use implicit stream to bool conversion
if (x.find(s) != string::npos) // string::npos - "bad" position.
cout << x << '\n'; // don't flush cout on every line
}
cout.flush(); // flush cout here
3. Try to assign more sensible names for your variables...
That's all...
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
thanx ArkM my programme is now more efficient but it is still leaving first six -eight line for example my first line consist of ID but when I searched for this it started showing the contnts from eight line is that me who is making mistake or really this is true.............I'm sending an attachment of file which I had tried to read...............
Well, and where is the attachment (zipped, I hope ;) ) and a corrected (but still incorrect ;) ) source?...
Have you ever heard about debuggers? I'm not sure that DaniWeb is the best debugging tool for C++ programs...
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
Simply present your code (with code tags ;) ) and problems description. Try to become familiar with your C++ installation debugger as soon as possible.
Good luck!
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348