Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<io.h>
- #include<sys\stat.h>
- #include<fcntl.h>
- #include<string.h>
- #include<stdio.h>
- #include<iostream.h>
- using namespace std;
- int fd; //file descriptor
- void escribir(){
- char mens[50];
- if((fd=creat("b.txt",S_IWRITE|S_IREAD))<0){
- cout<<"no se pudo crear el archivo"<<endl;
- return;
- }
- cout<<"mensaje: "<<endl;
- gets(mens);
- write(fd,mens,strlen(mens));
- close(fd);
- }
- void leer(){
- int k;
- if((fd=open("b.txt",O_RDONLY))<0){
- cout<<"no se pudo abrir"<<endl;
- return;
- }
- while(read(fd,&k,1)>0){
- cout<<k;
- }
- close(fd);
- }
- int main(){
- int opc;
- do{
- cout<<"1. escribir 2. leer 3. salir"<<endl;
- cin>>opc;
- switch(opc){
- case 1: escribir(); break;
- case 2: leer(); break;
- }
- }while(opc!=3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement