Functions and returning values

Is it possible to return something like a person's name from a function. This is the code I have but it keeps giving me errors. Please help!!

1
2
3
4
5
6
7
8
9
int names()
{ 
    char player_one[20];
    cout<<"Player 1 please enter your name"<<endl;
    cin>>player_one;
    cout<<"Player one's name is "<<player_one<<" !"<<endl;
    cin.get();
    return (player_one);
}
std::string

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <string>
#include <iostream>

using namespace std;

string names()
{
    string player_one;
    cout << "Player 1 please enter your name"<<endl;
    cin >> player_one;
    cout<<"Player one's name is "<<player_one<<" !"<<endl;
    cin.get();
    return (player_one);
}
Last edited on
Yes.
@Warnis ... How is that in anyway helpful? Especially after Disch gave a working example...

Although shouldn't cin>> be getline()?
Topic archived. No new replies allowed.