Problem Statement:
Writing and Reading student data in a file.

Detailed Description:
Write a program in which you have to:
1) Create a text file "Student_info".

2) Using Code Write the following data in it:

Roll NO   Student Name    Class
101        Ali Raza       BS(CS)
102         Usman         MS(CS)
103         Faizan        BS(CS)
104         Rehan         MIT
105         Ahmed         MCS

3) Open file and read data from it and display on the screen.

Sample Output
Student Information

Roll NO   Student Name    Class
101        Ali Raza       BS(CS)
102         Usman         MS(CS)
103         Faizan        BS(CS)
104         Rehan         MIT
105         Ahmed         MCS

Deadline
Your assignment must be uploaded/submitted on or before 18-06-2009.
For this I have developed following code. Plz correct it. I need it by 18th June 2009.

#include<iostream.h>
#include<fstream.h>
main()
char student_info, stname, clas;
int rno;
{
      char student_info[];

      int rno[10];

      char stname[50];

      char clas[30];

      ifstream inFile;

      char inputFileName[]=student_info.txt;

      inFile.open(inputFileName);

      if(!inFile)
      {
          cout<<"Cannot open input file named" <<inputFileName<<endl;
          exit(1);
      }
      while(!inFile.eof())
      {
          inFile>>rno>>stname>>clas;
          cout<< Roll No <<"\t"<<Student Name<<"\t"<<Class<<endl
          inFile.close()
      }
  }

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Mistakes :

1> We are not here to do your work here. If you are in such a hurry to submit it on 18th go do it yourself !!! Next time you say you need it this is our reply GO DO IT YOURSELF !!!,

(Since you have put in some effort...Have this...)

2> You better know what you are trying to do over here :

main()
char student_info, stname, clas;
int rno;
{

3> You are missing out on the double quotes.The file name is a string...

char inputFileName[]=student_info.txt;

It should be

char inputFileName[]="student_info.txt";

4>

inFile.open(inputFileName);

Better open this specifically in input mode mode as

inFile.open(inputFileName , ios::in);

5>

while(!inFile.eof())

Wrong style of coding read this.

6>

inFile>>rno>>stname>>clas;

You cannot just read in like this.Firstly you haven't allocated memory for stname clas rno and other strings to hold the values and you need to work on the delimiter you have used between the fields and other stuff to read the values properly.

Comments
Lots of good points

2> You better know what you are trying to do over here :

main()
char student_info, stname, clas;
int rno;
{

It's very old C-syntax, not valid anymore in C++ :P

>Better open this specifically in input mode mode as
He is doing fine: he declared the object of ifstream hence it is fine not to mention ios::in

To OP:
a. You coding is what use to be 15 years ago. I think it is time to change. Read this.
If your school forces you to use iostream.h and other deprecated coding style, you can do what they want in school but practice standard coding otherwise.
b. You should be posting the code using code-tags. Information about code-tag is posted all over the website :
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used
6) Even on the background of the box you actually typed your message in
So don't tell us that "you didn't knew about code-tags"

c. Please read How to ask questions the smart way and learn that it is yourproblem that you have to submit the assignment till 18th, not ours.

Comments
Lots of good points
This article has been dead for over six months. Start a new discussion instead.