Jump to content

  • Log In with Google      Sign In   
  • Create Account

Simple String input problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Uzumakis   Members   -  Reputation: 130

Like
0Likes
Like

Posted 03 November 2012 - 12:11 PM

[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

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9598

Like
1Likes
Like

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.

#3 Uzumakis   Members   -  Reputation: 130

Like
0Likes
Like

Posted 03 November 2012 - 12:26 PM

Thanks sir :) i got your point
i will try to avoid these typa mistakes again thanks again....... :)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS