copy iter->path() to a vector or array

Using the boost filesystem,
I need to get the output of cout into an array or vector


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 <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
#include <vector>
using namespace boost::filesystem;
using namespace std;

int loop_counter;
string srch_dir;
string results[10];

void initial_path( const path & directory, bool recurse_into_subdirs = true )
    {
    if( exists( directory ) )
    {
        directory_iterator end ;
            for( directory_iterator iter(directory) ; iter != end ; ++iter )
            if ( is_directory( *iter ) )
    {
    cout << iter->path() << " (directory)\n" ;
    if( recurse_into_subdirs ) initial_path(*iter) ;
    }
    else

//////////////////////////--See Below---////////////////////////

       cout << iter->path() << " (file)\n" ;  //<---I need this in a vector or array

/////////////////////////////////////////////////////////////////

    }
loop_counter++;
    }

 int main()
      {
       cout<< "Enter a Search Directory \n";
       cin >> srch_dir ;
       cin.ignore();
       initial_path( srch_dir ) ; 
       }
When you output to cout, just add it to the array/vector however you want to? Also, don't use \n with cout, use endl.
Last edited on
Thanks L B, I don't actually know how to add it to an array :)
I am a few days into learning c++
Could someone explain?

You can be assured I will appreciate your time.
Topic archived. No new replies allowed.