accessing directorys with fstream

working on boiler plate stuff to access a directory and stick the files in a vector here is the code the problem is it won't except a file folder only files with a specific extention. try the code out and try to pass a file folder fullpath name.

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
34
35
36
37
38
39
40
41
42
43
#include<iostream>
#include<cmath>
#include<fstream>
#include<stdlib.h>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	vector <string> filenames;
	char foldername [100];
	ifstream fileopen;
	cin.getline(foldername, 100);
	fileopen.open(foldername);

	if(!fileopen.is_open())
	{
		exit(EXIT_FAILURE);
	}

	string files;
	fileopen>>files;
	while(fileopen.good())
	{
		filenames.push_back(files);
		fileopen>>files;
	}
	sort(filenames.begin(),filenames.end());
	
	for(int i=0;i<filenames.size();++i)
	{
		cout<<filenames[i]<<endl;
	}



	system("pause");
	return 0;

}
Topic archived. No new replies allowed.