Click here to Skip to main content
15,894,410 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Opening a console window from a Windows form project Pin
David Crow24-Jul-06 8:15
David Crow24-Jul-06 8:15 
GeneralRe: Opening a console window from a Windows form project Pin
kialmur24-Jul-06 8:44
kialmur24-Jul-06 8:44 
GeneralRe: Opening a console window from a Windows form project Pin
Zac Howland24-Jul-06 8:53
Zac Howland24-Jul-06 8:53 
GeneralRe: Opening a console window from a Windows form project Pin
David Crow24-Jul-06 8:55
David Crow24-Jul-06 8:55 
Questionmouse & keyboard disabling Pin
RomTibi24-Jul-06 8:06
RomTibi24-Jul-06 8:06 
AnswerRe: mouse & keyboard disabling Pin
Chris Losinger24-Jul-06 8:36
professionalChris Losinger24-Jul-06 8:36 
AnswerRe: mouse & keyboard disabling Pin
Steve Echols24-Jul-06 14:08
Steve Echols24-Jul-06 14:08 
GeneralRe: mouse & keyboard disabling Pin
RomTibi25-Jul-06 7:47
RomTibi25-Jul-06 7:47 
QuestionTile View problem when using Owner Data [modified] Pin
Justin Tay24-Jul-06 7:54
Justin Tay24-Jul-06 7:54 
QuestionPreTranslateMessage not called?? [modified] Pin
Rob Hounsell24-Jul-06 7:40
Rob Hounsell24-Jul-06 7:40 
QuestionPassing a variable Pin
DanYELL24-Jul-06 7:16
DanYELL24-Jul-06 7:16 
AnswerRe: Passing a variable [modified] Pin
Harold_Wishes24-Jul-06 7:24
Harold_Wishes24-Jul-06 7:24 
GeneralRe: Passing a variable Pin
DanYELL24-Jul-06 7:40
DanYELL24-Jul-06 7:40 
GeneralRe: Passing a variable Pin
DanYELL24-Jul-06 7:44
DanYELL24-Jul-06 7:44 
QuestionRe: Passing a variable Pin
David Crow24-Jul-06 8:05
David Crow24-Jul-06 8:05 
AnswerRe: Passing a variable Pin
prasad_som24-Jul-06 19:00
prasad_som24-Jul-06 19:00 
Questioncin issues [modified] Pin
Harold_Wishes24-Jul-06 6:52
Harold_Wishes24-Jul-06 6:52 
AnswerRe: cin issues Pin
David Crow24-Jul-06 6:54
David Crow24-Jul-06 6:54 
GeneralRe: cin issues [modified] Pin
Harold_Wishes24-Jul-06 7:07
Harold_Wishes24-Jul-06 7:07 
QuestionRe: cin issues Pin
David Crow24-Jul-06 7:52
David Crow24-Jul-06 7:52 
AnswerRe: cin issues Pin
Harold_Wishes24-Jul-06 8:08
Harold_Wishes24-Jul-06 8:08 
GeneralRe: cin issues Pin
David Crow24-Jul-06 8:32
David Crow24-Jul-06 8:32 
GeneralRe: cin issues Pin
Zac Howland24-Jul-06 9:13
Zac Howland24-Jul-06 9:13 
This code looks vaguely familiar ... someone else was asking about a similar problem a couple weeks ago.

Anyway, the problem you are having is that when using cin, it ignores whitespace by default (that is, it sees it, but leaves it in the buffer). This is generally a problem only when reading in strings, but can happen in certain circumstances when reading other datatypes. Basically, this is what happens:

Lets say that the following string is in the read buffer for cin: MyString\n
cin will read "MyString" into the buffer and leave the \n on the read buffer.
Now, the next cin call will see the \n and assume an empty string.

An easy way to fix the problem would be to change:
DavidCrow wrote:
void add_number_of_subunits (int& data)
{
string buff;

do
{
cout << endl;
cout << "Please enter number of subunits: ";
cin >> buff;

} while (atoi(buff.c_str()) < 1 || atoi(buff.c_str()) > 12);

data = atoi(buff.c_str());
}


to be this instead:

void add_number_of_subunits (int& data)
{
    int check = 0;
     
    do
    { 	
        cout << endl;
        cout << "Please enter number of subunits: ";
        cin >> check; 
    } while (check < 1 || check > 12);	
 
    data = check; 
}


If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac

GeneralRe: cin issues Pin
David Crow24-Jul-06 9:22
David Crow24-Jul-06 9:22 
GeneralRe: cin issues Pin
Zac Howland24-Jul-06 9:30
Zac Howland24-Jul-06 9:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.