I am currently working on a program that is supposed to do the following:

I am supposed to take a data file of 5 student names that are in the following form: lastName firstName middleName. I am supposed to convert each name to the following form: firstName middleName lastName. The program must read each students entire name in a variable and must consist of a function that takes as input a string, consist of a students name, and returns the string consisting of the altered name. Use the string function FIND to find the index of ,; the function LENGTH to find the length of the string: and the function SUBSTR to extract the firstName, middleName, and lastName.

Here is my data file being used:
Miller, Jason Brian
Blair, Lisa Maria
Gupta, Anil Kumar
Arora, Sumit Sahil
Saleh, Rhonda Beth

Here is my program so far. I am not sure if I am on the right track or not.

#include <iostream>
#include <string>
#include <fstream>
#include <cassert>
#include <cfloat>

using namespace std;
int main()
ifstream fin;
assert ( fin.is_open());
int count=0;
double rading

fin >> reading;
if (fin.eof())break;

string outputname;
getline (cin, outputname);
ofstream fout (outputname.data());


void reverseName (char inName[], char outName[])
char firstname[40];
char lastname [40];char last[40];
char first [40];

strcpy(firstname, last);
strcpy(lastname, first);

strcpy(firstname, lastname);

strcat(lastname, last);
strcat(firstname, first);


Why are you using methods meant for C-style strings (strcpy and strcat) when you are using std::string objects? Otherwise the gist of all the inputs and outputs looks ok. Look up the substr and find methods and what they give for results. Hint: the += operator will be helpful to you.

This article has been dead for over six months. Start a new discussion instead.