loading a file into a vector?

I need help loading a file line by line into a string vector. My program keeps crashing as soon as it opens and i am not sure if i am doing it correctly. Please let me know what i am doing wrong and point me in the direction of correcting it. The idea is every line of text in the text file gets a spot in the vector, so first line of text would be in vector position [0], second in position [1], etc.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std; 

int main()
{

    int count = 0;
    vector<string> logs;
    string line;
    
    cout << "Testing loading of file." << endl;
    ifstream myfile ("weblog.csc226");
    if ( myfile.is_open() )
    {
         while ( ! myfile.eof() )
         {
               getline (myfile, line);
               logs.at(count) = line;
               count++;
         }
         myfile.close();
    }else{
          cout << "Unable to open file." << endl;
    }
    cout << "the log count is: " << count << endl;
    
    return 0;
}
I not that good with c++ but I believe that the fstream only handles *.txt. I don't know how to make it support other file extensions but someone else might.
no, the fstream supports the file i am calling for. I am able to take away the whole array thing any just put cout << line << endl; and it displays every line in the text file when i run the program. The program is loading correctly, i just dont know how to assign it to an array.
Instead of logs.at(count) = line; use this
logs.push_back(line);

alright, that worked. Thank you very much.
Topic archived. No new replies allowed.