How to use fstream?

Sep 27, 2018 at 8:40pm
Let's say I had a .txt file called "textFile1," and I wanted to record 5 lines of text from it.
1. text
2. file
3. example
4. lines
5. here

Now, in my main file, I want to record the values of each individual line into an array such as string words[5];

How would I go about assigning words[0]'s value to "text", words[1] to "file" and so on, so on?
1
2
3
4
5
6
7
8
9
10
11
int main()
{
    string words[5];
    /*how to open; How to set the value of each words variable to the respective 
     *lines of textfile1?  
     */
    for(int i = 0; i < 5; i++)
    {
        cout << words[i];
    }
}


I'm hoping to get the output "text file example lines here"
Sep 27, 2018 at 8:57pm
Already discussed many times
http://www.cplusplus.com/doc/tutorial/files/
Sep 27, 2018 at 9:06pm
I tried this but it did not help me. I need some clarification.
Sep 27, 2018 at 9:20pm
You tried what?
Sep 27, 2018 at 9:24pm
I looked over the link from above and struggled to fully understand it.
Sep 27, 2018 at 9:32pm
"Understanding fully" is overrated.

Surely you did understand some bits?
Topic archived. No new replies allowed.