這實際上是我的教練已經提供與我們的程序一起工作,我不得不做出一些改變迄今得到它至少編譯:錯誤:變量或字段宣佈無效
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <cctype>
#include <cstdio>
#include <string>
#include <list>
using namespace std;
std::string makeString();
std::string path= "/";
DIR*dirp;
struct dirent*direntp;
std::list<string> child_directories;
void dir_traverse(&path, ios::out){
list<string> child_directories;
DIR*dirp = opendir(path.data());
struct dirent*dir_entry = readdir(dirp);
while(dir_entry !=null){
unsigned char d_type = dir_entry->d_type==DT_OIR?'D' : 'R';
if(d_type == 'D'){
if(dir_entry->d_name[0]!= '.')
{
child_directories push_back(dir_entry_d_name);
}
}
out<<'\t'<<d_type<<":"<<dir_entry->d_name<<endl;
dir_entry= readdir(dirp);
}
list<string>::iterator it = child_directories.begin();
while(it! = child_directories.end())
{
dir_traverse(&path + "/" + *it, out);
it++;
}
closedir(dirp);
}
我得到作爲參考dir_traverse函數的標題,我有錯誤。我非常想知道是什麼導致了問題,爲什麼。我目前沒有真正理解的函數的一半,這可能是我遇到這個編譯問題的原因。只是沒有達到C/C++還沒有:)
感謝
速度上編輯:
void dir_traverse(string& path, ostream& out){
list<string> child_directories;
DIR*dirp = opendir(path.data());
struct dirent*dir_entry = readdir(dirp);
while(dir_entry !=NULL){
unsigned char d_type = dir_entry->d_type==DT_DIR?'D' : 'R';
if(d_type == 'D'){
if(dir_entry->d_name[0]!= '.')
{
child_directories.push_back(dir_entry_d_name);
}
}
out<<'\t'<<d_type<<":"<<dir_entry->d_name<<endl;
dir_entry= readdir(dirp);
}
list<string>::iterator it = child_directories.begin();
while(it != child_directories.end())
{
dir_traverse(&path + "/" + *it, out);
it++;
}
closedir(dirp);
}
在編譯器顯示錯誤的代碼中標記該行。 –
在改變它之前,dir_traverse()函數的標題看起來像什麼?更像'void dir_traverse(const std :: string&path,std :: ostream&out)'? – Johnsyweb
是的,它接近於:void dir_traverse(string path,ostream&out) – user975044