Hi all, I am wondering if anyone can help me as I havent been programming in c++ for a long time and just went back. I did some basic c++ before but kind of lost the touch.
The problem I am trying to do is return the values of an array of characters. See examples:
main.cpp
Code:
#include <cstdlib>
#include <iostream>
#include "PPlayer.h"
using namespace std;
int main(int argc, char *argv[])
{
system("cls");
PPlayer p;
p.addFN("hoang");
cout<<p.retFN();
system("PAUSE"); //<- console pause to see result before exiting
return EXIT_SUCCESS;
};
PPlayer.h
Code:
class PPlayer
{
char fname[30];
char lname[50];
int age;
public:
char* retFN();
void addFN(char[]);
};
PPlayer.cpp
Code:
#include <iostream>
#include "PPlayer.h"
char* PPlayer::retFN()
{
return fname;
}
void PPlayer::addFN(char fn[])
{
strcpy(fname,fn);
age = 1;
return;
}
It's pretty basic, as I am trying to do some test.
char * is a pointer and returning char* will return the address of the fname instead of the value in the array (I think that's what it does, cant remember my c++ much).
What i m wondering is, are there any other way of returning say the name enter : hoang
?