0

hi,
I am trying delete an old txt file and rename the new modified txt file... i followed everything from the example. However, i can't successfully rename the file. deletion is ok though. thank you.

void save(Name inName[], int j)
	{
		ofstream writer;
		writer.open("save.txt");

		for(int x=0; x<j; x++)
		{
			writer<<inName[x].getID()<<"\n"<<inName[x].getLastName()<<
"\n"<<inName[x].getFirstName()<<"\n"<<inName[x].getPhone()
<<"\n"<<inName[x].getAmt()<<"\n";
		}

		int resultRemove = remove("names.txt");
		if(resultRemove==0)
		{
			puts("removed");
		}

		else
		{
			perror("error");
		}

		int resultRename;

		char oldName[]= "save.txt";
		char newName[] = "names.txt";

		resultRename = rename(oldName, newName);

		if(resultRename==0)
		{
			puts("good");
		}

		else
		{
			perror("error");
		}

	}
2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Salem
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.