i'm trying to build a sample app for my students which should demonstrate how to enter multiple c-strings using cin.getline and cin.ignore but i'm getting weird results. in my code below there are two commented cin.ignore statements. if i uncomment first one then in runtime it is required to press Enter twice to input the first string and only once to input the second. if i uncomment second one instead then both strings inputted with one Enter but second string somehow lose first letter.
#include <iostream>
using namespace std;
struct Unit{
int uid;
char* name=new char[50];
char* shname=new char[10];
};
int main() {
Unit u;
cout << "Record number: ";
cin >> u.uid;
cout << "Unit name: ";
cin.ignore();
cin.getline(u.name,50);
//cin.ignore();
cout << "Unit short name: ";
//cin.ignore();
cin.getline(u.shname,10);
cout << "Record number: " << u.uid << endl
<< "Unit name: " << u.name << endl
<< "Unit short name: " << u.shname << endl;
return 0;
}
i cant quite understand what am i doing wrong