I am learning C++ at school and I am adding some functions to my school project. We need to code a program, which searches a word in files in folders.
I am at the point, where I want to list all directories and files and pass them back (with return), so I can display (output) them at the console.
So I used a vector type string and pushed back all the paths I found... Then I wanted to give (pass) them back with return, but I got the Error:
error: cannot convert `std::vector<std::string, std::allocator<std::string> >' to `std::string*' in return
Here is some Code:
string OpenFolder(string path, const string constSearchedWord)
vector<string> vIndex; //Vektor erzeugen
vector<string>::iterator i; //Iterator (zum durchlaufen)
...
while ( 0 != ( dirEntry = readdir( dirHandle ) ) )
{
string name = dirEntry->d_name;
fullPath = path + '\\' + name;
vIndex.push_back(fullPath);
}
//Den Ordner schliessen
closedir( dirHandle );
... If I wanted to write it into the console in this function:
for (i = vIndex.begin(); i < vIndex.end(); ++i)
{
cout << static_cast<string>(*i) << endl;
}
is working easily, but I don't want to write it in this function into the console.
I want to do
return vIndex;
I think the problem is in the header:
string OpenFolder(string path, const string constSearchedWord)
I tried
vector OpenFolder(string path, const string constSearchedWord)
But this didn't work either.
I don't know what to set here:
->???<- OpenFolder(string path, const string constSearchedWord)