Reading files that are in a folder

So what I'm trying to do here is get into the folder "emailaddress" and then read from the files that are inside it. The files inside emailaddress are named by numerical order and the type is just File not txt. I changed one of the files to a txt document so I could try to read it but my program isn't able to find the txt doc. I'm not getting any compile errors.

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
44
45
#include <iostream>
#include <fstream>
#include <string>
#include <dirent.h>
using namespace std;

int main()
{
	ifstream inFile;
	ofstream outputFile;
	ifstream inFile2;
	string shit;

	outputFile.open("email list");

	//OPEN EMAIL ADDRESS FOLDER
	DIR *dir;

	struct dirent *ent;
	if ((dir = opendir("emailaddress")) != NULL) {
		 int count = 0;
		
		/* print all the files and directories within directory */
		while ((ent = readdir(dir)) != NULL)
		{
			outputFile <<  count << endl;
			inFile2.open("1email.txt");

			if (!inFile2)
			{
				cout << "Cannot open input file. " << endl;
				return 1;
			}
			system("pause");
			count++;

		}
		closedir(dir);
	}
	else {
		/* could not open directory */
		perror("");
		return EXIT_FAILURE;
	     }
}
My guess is it's using a different working directory than that which contains the files. The ide is one way of changing this, but if you have any confusion you could try writing a new file and search for it? I'm sure there's a way to get the working directory as a string to print out though.
Topic archived. No new replies allowed.