Well the way I'm thinking of is to take input in main(), and store it into your variables using your setter functions. Then output it when needed using your getter functions.
e.g.
User.h
Code:
#include <iostream>
#ifndef USER_H /*Inclusion guards*/
#define USER_H
class User
{
public:
void vSetUserName(std::string); /*Function for setting the username, takes a string*/
void vSetAge(int); /*Function for setting the age, takes an int*/
std::string sGetUserName() const; /*Function for retrieving the username*/
int iGetAge() const; /*Function for retrieving the age*/
private:
std::string m_sUsername;
int m_iAge;
};
#endif /*USER_H*/
The next step is to define the class member functions in a source file:
User.cpp
Code:
#include "User.h"
void User::vSetUserName(std::string sUsername)
{
m_sUsername = sUsername; /*Store the contents of sUsername in m_sUsername*/
}
void User::vSetAge(int iAge)
{
m_iAge = iAge; /*Store the value of iAge in m_iAge*/
}
std::string User::sGetUserName() const
{
return m_sUsername; /*Return the variable to the program*/
}
int User::iGetAge() const
{
return m_iAge; /*Return the variable to the program*/
}
The final step is to use the functions to do as you please:
Main.cpp
Code:
#include "User.h"
int main()
{
User NewUser; /*Create a User object*/
std::string sTempUserName; /*Create a temporary variable for input*/
int iTempAge; /*Create a temporary variable for input*/
std::cout << "Enter Your Username: ";
std::cin >> sTempUsername; /*Store the user input in the temporary variable*/
std::cout << "\nAnd now your Age: ";
std::cin >> iTempAge; /*Store the user input in the temporary variable*/
NewUser.vSetUserName(sTempUserName); /*Set the username*/
NewUser.vSetAge(iTempAge); /*Set the age*/
std::cout << "\nYour Username is: " << NewUser.sGetUserName();
std::cout << "\nYour Age is: " << NewUser.iGetAge();
std::cin.get();
return 0;
}
This should do what you just explained.
NOTE - This was all off of the top of my head, so if you find bugs, point them out.