mhazami
سه شنبه 20 آبان 1393, 20:27 عصر
سلام دوستان. به نظرتون چرا قطعه کد زیر ایراد داره ؟
// autobackup.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
#include <dirent.h> // for read files and folders name
#include <Windows.h>
#include <time.h>
using namespace std;
bool exists(char* filePath)
{
//This will get the file attributes bitlist of the file
DWORD fileAtt = GetFileAttributesA(filePath);
//If the path referers to a directory it should also not exists.
return ( ( fileAtt & FILE_ATTRIBUTE_DIRECTORY ) == 0 );
}
void wait(int seconds)
{
int endwait;
endwait = clock() + seconds * CLOCKS_PER_SEC;
while (clock() < endwait){}
}
int main()
{
ofstream logfile;
DIR *dir;
struct dirent *ent;
string line;
bool file_exists = false;
cout << "checking changelog file ...\n";
wait(2);
if(exists("changelog.txt")){
cout << "opening changelog file ...\n";
logfile.open("changelog.txt");
file_exists=true;
wait(2);
cout << "changelog file opened.\n";
}
else{
cout << "creating changelog file ... \n";
logfile.open("changelog.txt");
wait(5);
cout << "done!\n\n";
}
wait(1);
system("CLS");
if ((dir = opendir ("e:\\share")) != NULL) {
/* print all the files and directories within directory */
if(file_exists==false){
while ((ent = readdir (dir)) != NULL) {
logfile << "\n" << ent->d_name;
}
logfile.close();
closedir (dir);
system("copy e:\\share e:\\download");
}
else{
if(logfile.is_open()){
while(getline(logfile,line)){
cout << line << '/n';
}
}
else{cout << "Unable to open file";}
}
} else {
cout << "could not open the directory";
}
_getch();
return 0;
}
توی خطی که از getline استفاده کردم، خطای no instance of overloaded function getline میده.
// autobackup.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
#include <dirent.h> // for read files and folders name
#include <Windows.h>
#include <time.h>
using namespace std;
bool exists(char* filePath)
{
//This will get the file attributes bitlist of the file
DWORD fileAtt = GetFileAttributesA(filePath);
//If the path referers to a directory it should also not exists.
return ( ( fileAtt & FILE_ATTRIBUTE_DIRECTORY ) == 0 );
}
void wait(int seconds)
{
int endwait;
endwait = clock() + seconds * CLOCKS_PER_SEC;
while (clock() < endwait){}
}
int main()
{
ofstream logfile;
DIR *dir;
struct dirent *ent;
string line;
bool file_exists = false;
cout << "checking changelog file ...\n";
wait(2);
if(exists("changelog.txt")){
cout << "opening changelog file ...\n";
logfile.open("changelog.txt");
file_exists=true;
wait(2);
cout << "changelog file opened.\n";
}
else{
cout << "creating changelog file ... \n";
logfile.open("changelog.txt");
wait(5);
cout << "done!\n\n";
}
wait(1);
system("CLS");
if ((dir = opendir ("e:\\share")) != NULL) {
/* print all the files and directories within directory */
if(file_exists==false){
while ((ent = readdir (dir)) != NULL) {
logfile << "\n" << ent->d_name;
}
logfile.close();
closedir (dir);
system("copy e:\\share e:\\download");
}
else{
if(logfile.is_open()){
while(getline(logfile,line)){
cout << line << '/n';
}
}
else{cout << "Unable to open file";}
}
} else {
cout << "could not open the directory";
}
_getch();
return 0;
}
توی خطی که از getline استفاده کردم، خطای no instance of overloaded function getline میده.