Populating a vector of strings.

SO I'm working with this right now:

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
#include <iostream>
#include <filesystem>
using namespace std;
using namespace std::tr2::sys;


void scan( path f, unsigned i = 0 )
{
	string indent(i,'\t');
	cout << indent << "Folder = " << system_complete(f) << endl;
	directory_iterator d( f );
	directory_iterator e;
	for( ; d != e; ++d )
	{

		cout << indent << 
			d->path() << (is_directory( d->status() ) ? " [dir]":"") <<
			endl;

		//if I want to go into subdirectories
		/*if( is_directory( d->status() ) )
			scan( f / d->path(), i + 1 );*/
	}
}
int main()
{
	path folder = "..";

	cout << folder << (is_directory( folder ) ? " [dir]":"") << endl;

	scan( folder );
}



This just goes through the directory where the file currently is and prints out it's contents. I'm just wondering how I might go about making a vector of string that contain all of the file names. Eventually I will have to sort those strings based on the file extension. So if there is a different container type you guys would reccomend that would be great too! Thanks!
I'm guess d->path is a string?

1
2
3
std::vector<string> fileNames;
string exampleFileName = "main.cpp";
fileNames.push_back(exampleFileName);


Though a lone vector isn't a terrific choice here. Quick and easy would be std::vector<std::list<string>>

The file name's extension is figured out before putting it in there:
1
2
3
4
5
6
Given a bunch of file names:
-Go through the vector looking at the first fileName in each list
-If the new name has the same extention as the name in the list
  push back onto that list
-If you get to the end of the vector without finding a match
  push back onto the vector
Last edited on
Thanks, that was extremely helpful!
Topic archived. No new replies allowed.