0

So this is my code so far...

    #include <iostream>
    #include <fstream>                
    #include <string>

            using namespace std;    
            int run_t = 0;
            char q_mos;

            class Destroyer_of_Worlds{
            public:
            string i_nput;
            string i_nput2;

            }lard;


int main () { //main executable


cout << "Would you like to write to the temporary datapcku database?\nSelect Y/N\n";

cin >>  q_mos;


if(q_mos == 'Y'){//phase one


    while(run_t==0){
    cout << "Running Input Operations.\n";

    //recieve input
    cout << "Please provide me with a Question so it can be achrived in the Active DB(Directory)\n";
    getline(cin, lard.i_nput);
    getline(cin, lard.i_nput);
    cout << "Recieved " << lard.i_nput << "at console line\n";

    //recieve input
    cout << "Please tell me the answer...\n";
    getline(cin, lard.i_nput2);
    cout << "Recieved " << lard.i_nput2 << "at console line\n";

    //terminate while loop        
    run_t=1;
    }





    } else {

    run_t=1;
    cout << "Booting into main operations...\n";


    }

cout << "At diagnostic Boot menu, prepare for diagnostic on system config         orginaztional routines.\n";
ofstream binlib;
binlib.open ("datapcku.bin", ios::app | ios::binary );
binlib << "Writing this to a file.\n";
binlib.close();
while(1){}
return 0;


}

However if you notice around line (34) you can see that I reiterate the getline( cin, lard.i_nput); two times. When testing this code it would skip right over the first instance of getline and prompt me for my 'answer' from the second one. Very quickly I realized I could by pass this by implementing an addition getline function call before the first one necessary for my program to fulfill its intended task. Does anyone have any idea on how to debug this?

1911 Soldier
  • 133
  • 1
  • 10
  • Put `cin.ignore(100, '\n');` on line 33. – druckermanly Oct 25 '16 at 15:48
  • 1
    consistent indentation helps for readability blank lines and lots of empty space does not – 463035818_is_not_an_ai Oct 25 '16 at 16:06
  • Wow. Works great. Thank you. I see how that works, perhaps I will replace my cin statements with getline from now on to ignore those pesky '\n' at the end of character arrays. I believe 100 may be to small for some of the arrays I plan to take with the program I am writing, would you mind elaborating its use? Can I make it larger? – 1911 Soldier Oct 26 '16 at 11:42

0 Answers0