Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I was assigned a project that required me to write a program that could ask a user for the name of a data file. This filed would contain a list of students in a class. The names are listed, one per line, in the following format:
lastName firstName middleInitial
Then, I have to take the firstName and lastName and concatenate them and add ".dat". Using the new firstNamelastName.dat format it would open the corresponding student's data file, read in their test scores, and then calculate the average.
None of my attempts at starting have been fruitful at all. :(

Hi Josh.
If you describe your attempts and maybe add some source code it would be possible to help you trace the problems...

Simple, simple
first you need a file stream
#include <fstream> //if 6.0 use fstream.h
using namespace std;int main() //i'm assuming this isn't a GUI
{char stringfirstname[80]; //First
char stringlastname[80]; //Last
char stringmiddlename[80]; //middleifstream getnames("file.txt"); //creates the file stream
while (!getnames.eof())
{
getnames >> stringfirstname; //get first name
getnames >> stringlastname; // get last name
getnames >> stringmiddlename; // middle name// do what ever you need to do here
}
}
hope that helps you. I'm not going to write the whole program for you (otherwise how are you going to learn?) remember that besides importing strings similar to cout cin, you can also you the get() and write() (not sure if that is right)

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |