cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
find specific line in txt file.
find specific line in txt file.
Feb 8, 2016 at 12:20pm UTC
Luisito07
(7)
...
Last edited on
Feb 13, 2016 at 2:51pm UTC
Feb 8, 2016 at 12:31pm UTC
Aceix
(1118)
You could read into a
std::string
type and then use the
find
algorithm to locate the date's entry position.
ref:
http://www.cplusplus.com/reference/algorithm/find/?kw=find
Last edited on
Feb 8, 2016 at 12:31pm UTC
Feb 8, 2016 at 12:47pm UTC
Chervil
(7320)
Since the date field is at the beginning of each line, you could read each line in turn, get the date which is
line.substr(0,10)
and test if it is equal to the user input date.
http://www.cplusplus.com/reference/string/string/substr/
To read a file line by line, see the second example in the tutorial under the heading,
Text files
http://www.cplusplus.com/doc/tutorial/files/
Topic archived. No new replies allowed.