I am using the following code which searches the file and provides the data and associated line number. But is this code fast enough in case of hundreds of thousands of lines? My PC literally froze for a few seconds. I need to search pair of integers and return its RHS value after comma (some statistical stuff), but with the following code I could able to return the whole line.
- Is it good idea in terms of fastness to parse the returned data using
splitfunctions and get my RHS value
OR
- Directly get RHS value based on LHS argument. (Well I am unable to do this)
Can anyone help me in achieving any one of the above two?
Here is my code:
#include <string> #include <iostream> #include <fstream> int main() { std::ifstream file( "index_hyper.txt" ) ; std::string search_str = "401" ; std::string line ; int line_number = 0 ; while( std::getline( file, line ) ) { ++line_number ; if( line.find(search_str) != std::string::npos ) std::cout << "line " << line_number << ": " << line << '\n' ; } } Here is my content of index_hyper.txt file:
18,22 20,37 151,61 200,62 156,63 158,64 159,65 153,66 156,67 152,68 154,69 155,56 156,14 157,13 160,122 161,1333 400,455 401,779 402,74 406,71