473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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,20);
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 3526

"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,20);
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,20);
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
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...
2
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...
2
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...
2
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...
3
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)...
3
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...
4
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>...
1
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...
1
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.