> Write a program which reads name,roll-number and age from a file named "student.dat" and display them.?

Write a program which reads name,roll-number and age from a file named "student.dat" and display them.?

Posted at: 2014-12-18 
In Python2: you can open the file with

file = open ("student.dat')

Edit:

You didn't give the format of the file.

One of the most important things a programmer has to have is attention to detail. Usually, by time a student is given an assignment to read from a file, they will have realized this.

You didn't say if the name would be just a first name or a full name. Even a first name can be a problem if, like Mary Jo, it contains a space. Will each data item be on a line by itself, or do you expect all 3 items to be on one line. If so, do you expect a comma to be between the items.

If the items are all on one line and you simply have to display them, the line could be read without any concern about what is on it and the line would simply be displayed as-is.

Since you didn't give those detail, I can't show you a C++ program, but I will give you a COMPLETE Python2 program that accomplishes what I described in the previous paragraph.

for line in open ("student.dat").readlines(): print line [:-1]

I suggest you start by attempting to write the same simple program in C++.

Or, if that's too much effort on your part, then maybe you should just drop the class. There is no reason to waste your time if you aren't interested in learning how to program.