• Advertisement
Sign in to follow this  

Simple String input problem

This topic is 1903 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Thanks sir :) i got your point
i will try to avoid these typa mistakes again thanks again....... :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement