Question: I am creating a text based game using C++ for a school project, the game works by allowing the user to pick a choice from a list of options in each scene; similar to how the games hosted by [Choice of Games](https://www.choiceofgames.com/category/our-games/) work. As a result of this I have a large amount of text that must be displayed in my game, however I am unsure as to the proper conventions when working with large amounts text in a program. Should I simply make use of **std::cout** and write the text directly into the code, or should I write into text files an used **std::ifstream** in order to read the text.

My only major concern regarding the use of files to hold the text is that each choice the user makes results in a different paragraph being displayed and as a result I believe that I would need to create a text file for each paragraph, which seems like it will lead to more issues (such as using the wrong file name or mistyping my code leading to the game reading from the wrong file) than writing the text straight into the code could. If there is a way to read particular sections of a text file then this would be useful to know, however I am currently unaware of any such method. However I am new to C++ and I am certain that there is plenty that I have yet to learn so I would not be surprised if such a method did exist.

Any help is greatly appreciated, be it anything from simply telling me if I should enter text into my code or into files, to telling me if there is a way to read text from specific sections of a text file. And once again, I am very grateful for any help you can provide.

Answer: 
I recommend using external files. It makes changing the content much easier and doesn't require recompiling the entire program for a simple typo.

You can use one file and just separate each paragraph with a blank line. Grabbing "all text between blank lines" at that point is trivial.

If the choices cause the paragraph choices to jump around the file you can give them IDs and load them on-the-fly by searching linearly through the file for a given ID.

--EDIT--

As per the request here is an algorithm or two:

Algorithm 1:

1. Give each paragraph an ID, usually a simple number on the line immediately above the paragraph.
2. Separate each number-paragraph pair by blank lines.
3. Parse the file line-by-line looking for a "line" that contains only a number.
4. From that point you found the paragraph you are looking for, all lines until the next blank is the content of that paragraph.
5. Display to user.

Algorithm 2 (recommended):

1. Use XML to store your paragraphs and their IDs.
2. Use TinyXML2 to parse the file: <http://www.grinninglizard.com/tinyxml2/index.html>
Storing text in the program files is not a good coding practice. This would result in unnecessary code bloat (it's not even code) and the need to recompile if you need to change the text.

A simple solution would be to create a text file with careful formatting like line numbers or whitespace that would allow you to pull out the desired text.

A more elegant solution would be to put the necessary text in xml or json files, and read them into your program when necessary. This would be a great choice.