Friday, April 24, 2009

File Modes

File Modes
We can use two arguments in the open() function, first argument is filename and the second argument is mode. The general form of the function open() with two arguments is
stream-object.open(“file_name”,mode);
here
File name
is sequence of string
Mode specifies the purpose for which the file is opened.

File Modes parameters
ios::app : Append to end of file
ios::ate: go to end of file on opening
ios::binary : Binary file
ios::in: Open file for reading only
ios:: nocreate: open fails if the file does not exists
ios::out: open fails if the file already exists
ios::out open file for writing only
ios::trunk: Delete contents of the file if it exists

Example:

#include<>
#include<>
void main()
{
char name[25],des[50];
int empcode;
clrscr();
ofstream f;
f.open(vvp.txt",ios::app);
cout<<"Enter Employee Name"; cin>> name;
f<<>> des;
f<<>> empcode;
f<<>> name;
fo>> des;
fo>> empcode;
cout>> name >> endl;
cout>> des >> endl;
cout>> empcode >> endl;
fo.close();
getch();
}

No comments:

Post a Comment