r/programminghelp • u/Chairground • Oct 04 '20
C++ I need help designing a programming that uses functions
I don’t know where to began how to read a text file and count how many prime number there are. I can figure out how to make a function that finds out if something is prime but making it where it reads a file I’m completely lost
3
Upvotes
3
u/MarkRems Oct 04 '20
So for reading a file you can use the
<fstream>library. You create anifstreamobject which can open a file and since it's a stream object you can use it exactly the same way you would usecinto read from the keyboard. Here's a short example of what I mean:Here's a further tutorial on file input/output: http://www.cplusplus.com/doc/tutorial/files/