I have created an app just to read person and client details. I have used an int for age, within a struct which works just fine. However I have created a long for mobile number within a class which ignores the value input and returns garbage. The Client.h file is shown below, Client.cpp just has #include "Client.h".
#pragma once
#include <string.h>
#include <iostream>
using namespace std;
class Client
{
public:
string firstname, lastName;
long mobile = 0;
};
The int Main() file contains the following:
//Client is a class created elsewhere in Client.h so we create an instance here a name it c.
Client c;
string name = "";
long num = 0;
//The details can then be entered for the client class
cout << "\nPlease enter client details:" << endl;
cout << "First name: ";
cin >> c.firstname;
cout << "Last name: ";
cin >> c.lastName;
cout << "Mobile phone: ";
cin >> c.mobile;
//before being converted into new variables for output (or storage)
name = c.firstname + " " + c.lastName;
num = c.mobile;
//and displayed to the console.
cout << "\nClient information: " << endl;
cout << "\nName: " << name << endl;
cout << "Mobile: " << num << endl;
return 0;
When run, the app performs fine and outputs all the string based variables perfectly but the value of long num (the c.mobile value) is just garbage. Any pointers to what I am doing wrong would be appreciated. Thank you in advance.