how to write a program using c++ that should read some particular data from a file?

hey..
can anyone tell me the code that could read some certain information from a file.
for example:
a program that should read basic information about a person from his resume.

please i need it urgently.
Last edited on
can you please help me by sending the code of the above program. I tried according to the link you sent but its not working so, please help me by sending the code.
Actually I am new to all this so, what all steps I could do was as under:

- we will first mention the header <fstream.h> through which we can read and write from files.
- we need to mention the location of the directory and the file in which the desired information is present.
- then we would open the file by using:
open <filename,mode>
since, we only need to copy the information from the file i.e. we have to read the information from the file, we will use <ios::out | ios::app> as the mode.
- Now, to read from file we would use stream:
ifstream myfile ("filename.txt")
if that particular file is open then we will grab the information by giving the line from which we need the data by using getline (myfile,line);
now we will print that information by cout << line << end1.

But the major problem with this is that we couldn't read the data simultaneously from many files. That could be made possible by using a loop function. Suppose, there are 'N' no. of files through which we have to read the data, so, we could run the loop from 1 to N and increment after every loop cycle.
ya..i got it.
now, i got the code.
Thank you buddy.
Now, please can someone help me in a program to search and compare various keywords in a file and then it should read all the contents from those respective lines in which words were found.
I worked on a code, but what all i could get was just to search for a word. How we would do it for multiple words then reading the full line in which word was present.
What all i worked on is as under:

#include
#include
void main(int argc,char *argv[])
{
int count=1;
char wd[20],word[20];
FILE *fp;
clrscr();
printf("enter the file name: ");
scanf("%s",argv);
fp=fopen(argv,"r");
if(fp==NULL)
{
printf("given file doesn't exist");
}
else
{
printf("enter the word to search");
scanf("%s",word);
fscanf(fp,"%s",wd);
while(!feof(fp))
{
if(strcmp(word,wd)==0)
{
printf("given word found in the file. the given word is the %d word in the file",count);
count=0;
break;
}
else
{
fscanf(fp,"%s",wd);
count++;
}
}
if(count!=0)
{
printf("given word is not found in the file");
}
}

PLEASE give the solution code. I need it urgently.
any answers ??
Topic archived. No new replies allowed.