ورود

View Full Version : سوال: چگونه خطای no instance of overloaded function getline را رفع کنم؟



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 میده.

rahnema1
چهارشنبه 21 آبان 1393, 07:14 صبح
سلام
به جای ofstream بذارید fstream logfile;
اگه می خواهید فولدر را هر 10 ثانیه یک بار کپی کنید بدون ovewrite اینجور هم میشه انجام داد

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
freopen("stdout", "w", stdout);
while(1)
{
system("echo no|copy /-y e:\\share e:\\download");
Sleep(10000);
}
}

mhazami
پنج شنبه 22 آبان 1393, 11:05 صبح
سلام
به جای ofstream بذارید fstream logfile;
اگه می خواهید فولدر را هر 10 ثانیه یک بار کپی کنید بدون ovewrite اینجور هم میشه انجام داد

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
freopen("stdout", "w", stdout);
while(1)
{
system("echo no|copy /-y e:\\share e:\\download");
Sleep(10000);
}
}


یعنی اینطوری فایل ها و پوشه های تکراری کپی نمیشه !؟

rahnema1
پنج شنبه 22 آبان 1393, 20:31 عصر
یعنی اینطوری فایل ها و پوشه های تکراری کپی نمیشه !؟

بله همین طوره