i have a simple code, i know it's something i'm just missing but i have no clue and tried searching online. so... i have a structure with two strings and one in as fields, now i use 'getline' to get both name and address but when i type in the phone number with cin.ignore i'm missing the first digit. here it is:
#include <iostream>
#include <string>
using namespace std;
struct Person_Information {
string Name;
string Address;
int phone_number;
};
int main ()
{
Person_Information Person;
cout << "Enter your Name: " << endl;
getline(cin, Person.Name, '\n');
cout << "Enter your address: " << endl;
getline(cin, Person.Address, '\n');
cin.ignore();
cout << "Lastly enter your phone number with (no '-' necessary)" << endl;
cin >> Person.phone_number;
cout << endl << endl;
when i type in the phone number with cin.ignore i'm missing the first digit.
That's exactly what cin.ignore() does, it reads and discards one character. In your case, it reads and discards the first digit of the phone number. If you need that digit, remove cin.ignore().
Ok I added cin.ignore() because i was getting the number 2147483647 that wildblue received back. wildblue what type should i use here ? i didn't know int had a limit. Thank you both