C Board  

Go Back   C Board > General Programming Boards > FAQ Board

 
 
LinkBack Thread Tools Display Modes
Old 10-22-2001, 07:18 PM   #1
Registered User
 
Join Date: Sep 2001
Posts: 9
file i/o

hello good people

can someone plz give an example (if poss wit a brief explanation)
on how to work with the funtions CreateFile, WriteFile, ReadFile.
i'm a bit mixed up with the arguments.
thanks in advance for your kind time

1976

"The truth is an amusing concept"
1976 is offline  
Old 10-24-2001, 03:55 AM   #2
Unregistered
Guest
 
Posts: n/a
try these

HERE ARE 2 EXAMPLES
USE ONE ATA TIME.





/********************FIRST EXAMPLE**********************************/
/****************
writes or appends info to a text file
****************/

#include<iostream.h>
#include<fstream.h>

void main()
{
//setup a new stream (tube) and give it a name

ofstream outfile;

//now connect it to a text file
//then open it


//delete the first "//" from either ONE of the next two lines
//outfile.open("C:\\testfile.txt");//this writes over existing text
//outfile.open("C:\\testfile.txt,ios::app");//this appends to existing text

//send data
outfile<<"YOUR NAME HERE"<<endl;
outfile<<"PORTUGAL"<<endl;
outfile<<"DID IT WORK?"<<endl;


//now give some info on screen
//all go well?????
cout<<endl<<"file written\n";


}//end first example

/****************SECOND EXAMPLE**********************/

/*******************
reads from a file and displays info to screen
**********************/

#include<iostream.h>
#include<fstream.h>//needed for string functions

void main()
{

char first_name[25];//[25] characters allowed
char last_name[25];
char subject[25];
char sector;

//setup file stream
//first setup and name an input file
ifstream infile;//call it infile

//now associate it with a file
infile.open("C:\\readtest.txt");

/* create a file C:\readtest.txt
using notepad (or equivelant) and write this in file
YOUR christian name
YOUR surname
YOUR location
YOUR gender
then save as C:\readtest.txt*/


//now read it
infile>>first_name;
infile>>last_name;
infile>>location;
infile>>gender;

//close it!!!
infile.close();

//now display
cout<<endl<<"first name:- "<<first_name;
cout<<endl<<"last name:- "<<last_name;
cout<<endl<<"location:- "<<location;
cout<<endl<<"gender:- "<<gender;

cout<<endl<<endl;

}//end reading example

/************************************************** *********/
 
 

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Structure Eror prominababy C Programming 3 01-06-2009 09:35 AM
File I/O Assertion Failure in VS2008 clegs C Programming 5 12-25-2008 04:47 AM
Game Pointer Trouble? Drahcir C Programming 8 02-04-2006 02:53 AM
Unknown Memory Leak in Init() Function CodeHacker Windows Programming 3 07-09-2004 09:54 AM
advice on file i/o Unregistered C Programming 1 11-29-2001 05:56 AM


All times are GMT -6. The time now is 04:32 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22