Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Simple String input problem

4: Adsense

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   

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

#2 SiCrane   Moderators   

11763
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   

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.