why won't this read my file?

everytime I try to run this code I get some weird error, saying unhandled exception at so and so memory address.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;



int main(){
	
	ifstream config("C:/test/config.txt");
	string Aconfig[3];
	int counter = 0;
	while(!config.eof()){
		getline(config,Aconfig[counter]);
		cout << Aconfig[counter] << endl;
		counter++;
	}

	char y;
	cin >> y;
	return 0;
}


I'm completely stumped by this, any help is appreciated.
Have you checked that you don't read more than 3 lines, which would cause a bufffer overflow?
oh wow, I'm stupid. My array that I was storing it in wasn't big enough......

is there any way to check how many lines the file is, and put that as the array size?
Not without parsing the whole file first. But you can use a vector of strings, which will resize itself as you add strings to it
Topic archived. No new replies allowed.