473,408 Members | 1,747 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,408 software developers and data experts.

Maybe dumb question... but really appreciate for help.

I'm currently using the following statements inside "Do.. While" loop

cout << "Please enter the file name: ";
cin.getline(FileName, 19, '\n')

On the first execution, everything works ok, but when the 'while' condition is met and it goes back to the beginning of the while loop to execute the statement again, it won't stop for user input any more. (That is before cin.getline(FileName, 19, '\n'); ) The code fails because it can't read the input when it's being executed at the second time. Why is it happening
Should I code differently when I ask for user input inside loop

Thanks in advance for your help!!
Nov 17 '05 #1
1 2162
Ryan <an*******@discussions.microsoft.com> wrote:
I'm currently using the following statements inside "Do.. While" loop.

cout << "Please enter the file name: ";
cin.getline(FileName, 19, '\n');

On the first execution, everything works ok, but when the 'while'
condition is met and it goes back to the beginning of the while
loop to execute the statement again, it won't stop for user input
any more. (That is before cin.getline(FileName, 19, '\n'); )
The code fails because it can't read the input when it's being
executed at the second time. Why is it happening? Should I code
differently when I ask for user input inside loop?
It is likely something goes wrong with
your input. Then 'std::cin' enters a
bad state and will refuse to do any
input. You should check for it to be
good ('std::cin.good()') in your loop
as well.
Also, using 'std::string' would most
probably be easier:
std::string filename;
std::getline(std::cin,filename);
You can get an old-fashioned C style
string ('const char*') from it by
calling 'filename.c_str()'.
Thanks in advance for your help!!


HTH,

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"Sometimes compilers are so much more reasonable than people."
Scott Meyers

Nov 17 '05 #2

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

Similar topics

0
by: ted holden | last post by:
Dumb questions: Suppose you have an application which shows text and a corresponding mpeg video file. The user does a search and clicks one of the hits, the text around the hit shows up in one...
3
by: ed | last post by:
I've just started working with .Net, so appologize for what is probably a really dumb question. Did Windows XP originally come with the .Net framework installed, and if so which version? ...
12
by: Joe | last post by:
Hello All: I'm sure that one of you can quickly spot the error in my script. I am using a small javascript function to retrieve the text of a hyperlink in a datagrid column. Here is my...
5
by: Wayne Dixon | last post by:
Ok, I know this is going to sound like a really stupid quesiton, but does anybody know how to load a form from a click event? I've tried my standard VB6 code tricks, of course to no avail. ...
1
by: Bob | last post by:
Vs2055, vb.net. I have two related datagridviews they're both bound to related tables. Best way to give idea is as follows. Parent datagrid is a list of companies. Child datagrid is a list of...
16
by: CMM | last post by:
Is it me or has anyone noticed that F1 is really dumb in VS2005. Since VB3 I have been able to click F1 on an ambiguous method in code and the IDE automatically determines the type based on the...
20
by: James | last post by:
I am new to vb.net (I am an old vb6 programmer). I cannot figure out an easy way to watch variables. In vb6 all I did was right click and could chose to stop execution when a variable chances as...
4
by: theapeman | last post by:
Sorry to bore everyone with this question, which I'm sure is the equivalent of "Please help! What letter comes between C and E in the alphabet?" but seriously, if you really didn't know that, I don't...
8
by: Keith Rebello | last post by:
I have a program whose main form has a picture box on which concrete column sections are drawn. Input to the drawing is achieved by filling in data in various dialog boxes (called by using...
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
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,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.