I want to use the push_back function to fill my vector with lines from a text file. But it overwrites all entries with the last line. Here is the source code:
int main() {
std::vector<char*> lines;
FILE* file;
file = fopen("textfile.txt", "r");
const size_t max_line_length = 1000;
char line[max_line_length + 1];
while ( !feof(file)) {
fgets(line, max_line_length, file);
lines.push_back(line);
}
fclose(file);
}
Hope somebody can help.