[source lang="cpp"]#include "stdafx.h"#include<iostream>#include<conio.h>#include<stdio.h>#include<string>#include<string.h>using namespace std;void main(){ string a,b; char dchoice='y'; do{ cout<<"PLease enter the string"<<endl; getline(cin,a); cout<<"Please enter the Second String"<<endl; getline(cin,b); cout<<"String one"<<a<<endl; cout<<"String two"<<b<<endl; cout<<"To continue please enter y"<<endl; cin>>dchoice; }while(dchoice=='y');}[/source]
okay i am trying to take the input of the two string the first time the loop iterates it take's the input accurately while the second time it misses the first input of the string can any one give me a solution and point me where i am going wrong
2 replies to this topic
Sponsor:
#2 Moderators - Reputation: 6662
Posted 03 November 2012 - 12:18 PM
Using the extraction operator on a char reads one char and leaves whatever other input is in the buffer in the buffer. You'd want to flush the buffer in order for your subsequent reads to make sense. One way is to just use getline() for every input and look for the 'y' in the resulting stream.






