getline skips

<SOLVED>

I'm using 2x getline, but for some reason it skips over the first one and just adds the info to the 2nd one

afaik it had something to do with buffer and fixed by using cin.ignore or whatever but that was for "char", I'm using "string". Thank you

getline(cin,bla1);
getline(cin,bla2);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <ostream>
#include <string>

using namespace std;

template <class PACKAGE>
class DATE_EXP{
PACKAGE NAME_EXP,ADRESS_EXP;
public:
DATE_EXP(PACKAGE first,PACKAGE second){NAME_EXP=first,ADRESS_EXP=second;}
void INSERT_DATE_EXP (){
getline(cin,NAME_EXP);
getline(cin,ADRESS_EXP);
cout << "NAME_EXP IS " << NAME_EXP << "\n";
cout << "ADRESS_EXP IS " << ADRESS_EXP << "\n";
 }; //void INSERT_DATE_EXP ()
 }; //class DATE_EXP

template <class PACKAGE>
class KG_GC{
PACKAGE KG,GC;
public:
KG_GC(PACKAGE first,PACKAGE second){KG=0,GC=0;} 
void INSERT_KG_GC ();
void VIEW_KG_GC ();
void NORMAL ();
 }; //class KG_GC{
template <class PACKAGE>
void KG_GC<PACKAGE>::INSERT_KG_GC (){
cout<<"KG:";cin>>KG;
cout<<"GC:";cin>>GC;
 } //void INSERT_KG_GC
template <class PACKAGE>
void KG_GC<PACKAGE>::VIEW_KG_GC (){
cout<<"KG:"<<KG<<"\n";
cout<<"GC:"<<GC<<"\n";
 } //void INSERT_KG_GC
template <class PACKAGE>
void KG_GC<PACKAGE>::NORMAL (){
cout<<"NORMAL_COST:"<<KG*GC<<"\n";
 } //void NORMAL

/* -------------------------- here is the problem V
class ONEDAY: public KG_GC<double>{
public:
void ONEDAY_1 (): KG_GC<double>
 };
template <class PACKAGE>
void KG_GC<PACKAGE>::ONEDAY (){cout<<"ONEDAY:"<<10<<"\n";}
*/

int main(){
int A0=0;
do{cout<<"CHOOSE PROGRAM NUMBER:25\n";int B0=25;switch(B0){
case  1:{cout << " 0=EXIT\n 1=COMMAND LIST\n25=2505111-T2-2-1\n";break;}
case  0:{return 0;}
case 25:{
int ghost=0;cin>>ghost;cout<<endl;cin.ignore(); //clear buffer
string NAME_EXP_TEMP, ADRESS_EXP_TEMP;
DATE_EXP<string> EXP_TEMP(NAME_EXP_TEMP,ADRESS_EXP_TEMP);
EXP_TEMP.INSERT_DATE_EXP();

double KG_TEMP = 0,GC_TEMP = 0;
KG_GC<double>KG_GC_TEMP(KG_TEMP,GC_TEMP);
KG_GC_TEMP.INSERT_KG_GC ();
KG_GC_TEMP.VIEW_KG_GC ();
KG_GC_TEMP.NORMAL ();




//CALC_COST<double>CALC_COST_2(1,2);
//CALC_COST_2.DA_REZULTATU ();
cout << "put A0:";cin >> A0;cout<<"A0="<<A0<<"\n";


 break;}//switch B0=25
 }//switch B0
 }while(1);//doodoo
    return 0; //TEMP 17-1-1
 }//main



/*
void INSERT_KG_GC (){
double KG2=KG+1000,GC2=GC+1000;
cin >> KG;
cin >> GC;
cout<<"KG:"<<KG<<"\n";
cout<<"GC:"<<GC<<"\n";
KG=KG2+1;
GC=GC2+1;
cout<<"KG2:"<<KG2<<"\n";
cout<<"GC2:"<<GC2<<"\n";
 }; //void INSERT_KG_GC ()
*/
Last edited on
cin.ignore should still fix it. Where did you try to put it? It would be best to have one after each >> (unless they are consecutive)
@ OP: About Line 62, why would you do something like that?

About your issue, it's a personal preference in this case but std::cin.sync() would also work. Here's a link: http://www.cplusplus.com/reference/iostream/istream/sync/
Topic archived. No new replies allowed.