473,545 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cin.getline & cin>> interference

Hi,

I don't remember if it happened previously, but nowadays
I'm having problem with using cin.getline function and
cin>> function simultaneously.

I have Visual Studio 6. If I use cin.getline function at
first and then I use the cin>> function then the next time
cin.getline function does not work.

Eg:-

cout<<"a::";
cin.getline(a, 20);
cout<<"Num::";
cin>>Num;
cout<<"b::";
cin.getline(b,2 0);
cout<<"c::";
cin.getline(c, 20);

Now in output it will input for 'a' then 'Num' but it will
leave input for 'b' and then it will input for 'c'.

Please do help me with this problem.

Thanks,
Vikram.
Jul 21 '05 #1
2 3543

"Vikram" <vi****@softkee .com> wrote in message
news:05******** *************** *****@phx.gbl.. .
Hi,

I don't remember if it happened previously, but nowadays
I'm having problem with using cin.getline function and
cin>> function simultaneously.

I have Visual Studio 6. If I use cin.getline function at
first and then I use the cin>> function then the next time
cin.getline function does not work.

Eg:-

cout<<"a::";
cin.getline(a, 20);
cout<<"Num::";
cin>>Num;
cout<<"b::";
cin.getline(b,2 0);
cout<<"c::";
cin.getline(c, 20);

Now in output it will input for 'a' then 'Num' but it will
leave input for 'b' and then it will input for 'c'.

Please do help me with this problem.

Thanks,
Vikram.


That's because cin >> leaves the return character in the input buffer, which
is then picked up by cin.getline().
Check out cin.ignore(100, '\n') to use between the cin >>'s and
cin.getline()'s .

--
Peter [MVP Academic]
Jul 21 '05 #2

"Vikram" <vi****@softkee .com> wrote in message
news:05******** *************** *****@phx.gbl.. .
Hi,

I don't remember if it happened previously, but nowadays
I'm having problem with using cin.getline function and
cin>> function simultaneously.

I have Visual Studio 6. If I use cin.getline function at
first and then I use the cin>> function then the next time
cin.getline function does not work.

Eg:-

cout<<"a::";
cin.getline(a, 20);
cout<<"Num::";
cin>>Num;
cout<<"b::";
cin.getline(b,2 0);
cout<<"c::";
cin.getline(c, 20);

Now in output it will input for 'a' then 'Num' but it will
leave input for 'b' and then it will input for 'c'.

Please do help me with this problem.

Thanks,
Vikram.


That's because cin >> leaves the return character in the input buffer, which
is then picked up by cin.getline().
Check out cin.ignore(100, '\n') to use between the cin >>'s and
cin.getline()'s .

--
Peter [MVP Academic]
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
10545
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script type="text/javascript"> <!]> </script> <script type="text/javascript"
2
22929
by: Francesco Moi | last post by:
Hello. I designed a form to edit some DataBase's fields. But some of these fields contain '&lt;' and '&gt;' characters. And these characters are '<' and '>' in HTML. So if want to edit these fields, the form converts them into '<' and '>'. And I want to mantain '&lt;' and '&gt;' Mi piece of code:
2
6828
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node as a value. Check out the following problem. I want to convert the value in <WpDatesXml> node to have a valid "<" and ">" instead of &lt or &gt...
2
372
by: Vikram | last post by:
Hi, I don't remember if it happened previously, but nowadays I'm having problem with using cin.getline function and cin>> function simultaneously. I have Visual Studio 6. If I use cin.getline function at first and then I use the cin>> function then the next time cin.getline function does not work.
3
4631
by: ax | last post by:
to implement std::cout and file output seems simple but for file input and cin i have some question for the "std::cin" #include <iostream.h> int main(void) {int n, sum=0; while(cin >> n) sum+=n; cout << "somma = " << sum << endl; return 0;
3
5287
by: moleskyca1 | last post by:
In C++ FAQ (15.5), I see this code: int i = 0; while (std::cin >x) { // RIGHT! (reliable) ++i; // Work with x ... } but I don't know how can while loop end? ostream &operator >>(...) return ostream &. how can that ever end the while loop? Is it because there is hidden operator to cast to int? I cannot figure out, please help?
4
11897
by: mark4asp | last post by:
I have an element, report which contains tags which have been transformed. E.g. <pis &lt;p&gt <myXml> <report>This text has html tags in it.&lt;p&gt which but <has been changed to &lt;&gt</report> </myXml> I there a way that the XSLT transformation can render the content as html rather than text?
1
2043
by: edyam | last post by:
Because of a simple cin statement, my program goes into an infinite loop and I'm not sure why. I've used the same code in other programs (only with different variable names and cout statements) and it's worked fine. See code below: int main () { BinaryHeap pQueue; // create empty heap bool acceptCommand = true; string command; //...
1
4299
by: ismailc | last post by:
Hi, I need help please. Update system to to new version & moved on to .Net2 But now my code that worked in my .Net1 xslt does not work. .Net1 fine: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:asp="remove" xmlns:igchart="remove" xmlns:igsch="remove"> &lt;td class='rowDet' id="td_<xsl:value-of...
0
7468
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
5972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5329
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1884
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
704
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.