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
reading text files
reading text files
Mar 23, 2018 at 8:24pm UTC
ZLAPQM
(5)
how would i make a program that:
-reads a text file
-user inputs a string
-looks for that string phrase and prints the rest of that line
Text file:
1
2
3
Ape 5
// just prints 5 when ape is entered
Boy 10
// 10
Dog 11
// 11
Mar 23, 2018 at 8:35pm UTC
sollhost
(1)
Take a look at these pages:
http://www.cplusplus.com/doc/tutorial/files/
http://www.cplusplus.com/doc/tutorial/basic_io/
http://www.cplusplus.com/reference/string/string/find/
They should give you some idea on how to do that.
Mar 23, 2018 at 8:36pm UTC
Repeater
(3046)
Reading from text file:
http://www.cplusplus.com/doc/tutorial/files/
User input, and output:
http://www.cplusplus.com/doc/tutorial/basic_io/
Break the problem down, do it slowly, get each step working first.
Start with reading from the file and outputting every line. Then you're halfway there.
Mar 23, 2018 at 9:38pm UTC
zaphraud
(157)
I wouldn't bother doing it in that order.
I would ask the user for the string, then read thru the text file line by line, producing the output.
Way easier that way.
Are you required to read the whole file before asking about it?
Topic archived. No new replies allowed.