1
#include <iostream>
#include <string.h>
#include <fstream>
#include <conio.h>


int main()
{
    int k=0;
    char *source = new char[30];
    char *destination = new char[30];
    while(k==0)
{
    cout<<"Enter the source File location: ";
    cin>>source;
    cout<<endl<<"Enter the destination File location: ";
    cin>>destination;
    ifstream is(source,ios::in | ios::binary);
    ofstream os(destination,ios::out | ios::binary);

    if(is==NULL || os==NULL)
    {
        perror("Either the input or the ouput location is invalid");
        cout<<endl<<"Try again with new location.\n";
        cout<<endl<<"To exit press 7 and to continue press 0";
        cin>>k;

    }
    else
    {

                    os<<is.rdbuf();
        k++;
        cout<<endl<<"File moved successfully";
        cout<<endl<<"Do you want to delete the original file: [y/n]";
        if(getch()=='y')
        {
            if(remove(source)== -1) 
            perror("Error in deleting File");
            else
            cout<<" Source File deleted.";
        }

    }
}
}

ファイルは正常に削除されましたが、ファイルの削除中に次のように表示されます。

「ファイルの削除中にエラーが発生しました」権限が拒否されました。

ソースアドレスと宛先アドレス(C:/MIT/adi.txtなど)を要求するときに両方の種類のスラッシュ(前方と後方)を使用し、mingwコンパイラを使用してコンパイルしています...それはOSエラーですか、それともコードまたはコンパイラに問題はありますか?

4

1 に答える 1