Display first letter of string from a template

#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
using namespace std;

template < class T>
T inputData (T fName, T lName)
{
cout << "Please input your first name: ";
cin >> fName;
cin.ignore();
cout << "Please input your Last name: ";
cin >> lName;
cin.ignore();
return (fName + lName);
}

int main ()
{
string fName;
string lName;
cout << inputData(fName[0], lName[0]);
return 0;
}
I am trying to display the first letter of the first and last name next to one another. However whenever I run this it tries to input the last name as a data type.
inputData(fName[0], lName[0]);

fName[0] and IName[0] are of type char. So here is the function you're calling:


1
2
3
4
5
6
7
8
9
10
char inputData (char fName, char lName)
{
cout << "Please input your first name: ";
cin >> fName;
cin.ignore();
cout << "Please input your Last name: ";
cin >> lName;
cin.ignore();
return (fName + lName);
}


So the input is trying to be stored in a single char, and the returned value is a single char. I suspect this is not at all what you meant to do.
no not at all. thank you
Topic archived. No new replies allowed.