accessing directories

Hi I am working on boiler plate code to access a directory and push_back the file names found in that directory to a vector so that I can work with them sorting by name and extension type. Right now I am trying to get access to a folder file on my desktop so that the files inside can be stored here is the code so far.
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 word;
	fileopen>>word;
	while(fileopen.good())
	{
		filenames.push_back(word);
		fileopen>>word;
	}
	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.