I have a series of large text files (10s - 100s thousand lines) that I want to parse a line. The idea is to check if the string has a specific word / character / phrase and is currently writing to an additional file if this happens.
The code I've used so far:
ifstream infile1("c:/test/test.txt"); while (getline(infile1, line)) { if (line.empty()) continue; if (line.find("mystring") != std::string::npos) { outfile1 << line << '\n'; } }
The ultimate goal is to write these lines to the database. I thought to write them to a file first and then import the file.
The problem that I encountered is the time taken to complete the task. I try to minimize time as much as possible, so any suggestions regarding saving time on the read / write scripts above would be most welcome. Sorry if something is obvious, I just started to switch to C ++.
thanks
EDIT
I have to say that I am using VS2015
EDIT 2
So, it was my own mistake, when I switched to Release and changed the type of architecture, I had a noticeable speed. Thanks to everyone who pointed me in this direction. I also look at mmap material and this is also useful. Thanks guys!
source share