我很沮丧。我试图找到一种方法来获取名为'line'的变量,以便在代码底部的for循环内访问。
#include <ctime>
#include <iostream>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <vector>
#include <string>
#include <iostream>
#include <Lmcons.h>
#include <fstream>
#include <windows.h>
using namespace std;
string currentmonth;
string earlydays;
//**************************************
string a3;
string a1;
int getdir (string dir, vector<string> &files)
{
DIR *dp;
struct dirent *dirp;
if((dp = opendir(dir.c_str())) == NULL)
{
cout << "Error(" << errno << ") opening " << dir << endl;
return errno;
}
while ((dirp = readdir(dp)) != NULL) {
std::string fname = dirp->d_name;
if(fname.find("FIN804") != std::string::npos)
files.push_back(fname);
}
}
//***************************************
int main() {
//Copy New date to be used from date database
ifstream dailyfiledate;
dailyfiledate.open("Databasedate.txt");
string line;
if (!dailyfiledate) //checks to see if file opens properly
{
cerr << "Error: Failed to copy the first string from Date Database.";
}
else
{
if (getline(dailyfiledate, line)) // Get line
cout << line; // print the line.
dailyfiledate.close(); // Remember to close the file.
}
string dir = string(a1);
vector<string> files = vector<string>();
getdir(dir,files);
for (unsigned int i = 0; i < files.size();)
{
//cout << files[i] << endl;
a3 = files[i];
cout << a3 << endl;
string b1 = a3 + line;
cout << b1 << endl;
remove(b1.c_str());
i++;
}
}
答案 0 :(得分:0)
实际上,变量在for循环中成功到达。我想这是对我的道路的疏忽。
上面的代码在编译时绝对没有错误。
你真的需要更加谦虚。给出答案,给予指导,或者根本不发表评论。