cannot remove and rename the file
Mar 24, 2017 at 1:52pm UTC
OS: Window 10
Compiler : Visual Studio 15
Error : file is not renamed : permission denied
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
void deleteuser()
{
// header file
// #include<iostream> #include<stdlib.h> #include<string>
ifstream data;
int check;
ofstream data1("temp.txt" );// dummy data will be store
data.open("file.txt" ); // file with student data
string name, id, gpa;
if (data.good())
{
string del;
cout << "\nEnter the student you want to delete : " ;
cin >> del;
while (data >> id&&data.ignore(40, '\n' ), getline(data, name) && data>>gpa)
{
if (del != id)
{
data1 << id << endl;
data1 << name << endl;
data1 << gpa << endl;
}
else
{
cout << "\nStudent Seccussfully deleted" ;
}
}
}
else
{
cout << "\nFile Not Found\n" ;
}
remove("file.txt" );
check=rename("temp.txt" , "file.txt" );
if (check == 0)
puts("File is Successfully renamed" );
else
perror("File is not renamed" );
}
Last edited on Mar 24, 2017 at 2:01pm UTC
Mar 24, 2017 at 2:07pm UTC
You need to close both streams data
and data1
before attempting remove or rename.
Mar 24, 2017 at 2:16pm UTC
now i am getting this error after closing data and data 1
1 2
Severity Code Description Project File Line Suppression State
Error C3867 'std::basic_ofstream<char,std::char_traits<char>>::close' : non-standard syntax; use '&' to create a pointer to member file headling e:\visual studio\file headling\file headling\source.cpp 94
Last edited on Mar 24, 2017 at 2:16pm UTC
Mar 24, 2017 at 2:20pm UTC
ouh i forgot to put brackets in close now it is working thnx @Chervil you the best
Last edited on Mar 24, 2017 at 2:20pm UTC
Topic archived. No new replies allowed.