Click here to Skip to main content
15,900,589 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CString question Pin
Mukkie27-Jan-04 7:48
Mukkie27-Jan-04 7:48 
GeneralRe: CString question Pin
Antti Keskinen27-Jan-04 7:52
Antti Keskinen27-Jan-04 7:52 
GeneralRe: CString question Pin
Carlos Antollini27-Jan-04 8:06
Carlos Antollini27-Jan-04 8:06 
GeneralRe: CString question Pin
Antti Keskinen27-Jan-04 9:19
Antti Keskinen27-Jan-04 9:19 
Generalwhile loop problem Pin
CarteBlanche27-Jan-04 7:28
CarteBlanche27-Jan-04 7:28 
GeneralRe: while loop problem Pin
b_girl27-Jan-04 7:34
b_girl27-Jan-04 7:34 
GeneralRe: while loop problem Pin
CarteBlanche27-Jan-04 7:37
CarteBlanche27-Jan-04 7:37 
GeneralRe: while loop problem Pin
Antti Keskinen27-Jan-04 7:43
Antti Keskinen27-Jan-04 7:43 
This is because you use the standard input stream (cin). This will read characters from the input stream into the designated buffer. As you will first type 'Y' and then press enter, the rSearch will end up showing the NULL character '\0'.

If you are using Visual Studio and/or Windows OS, consider utilizing the _getch function instead of the standard input stream. See MSDN with a keyword for more information about the function.

Code example:
#include <conio.h><DIV>// Later in the code<DIV>
char rSearch;
do
{
   cout << "Search again ? (Y/N): ";
   _getch( rSearch );
   rSearch = toupper( rSearch );
} while ( rSearch != 'Y' && rSearch != 'N' );


If you are programming on Linux and thus have no access _getch, consider creating a buffer of two or more characters, then using the input stream operation again, only this time checking the first character of the buffer. However, if user inserts more characters than the buffer can hold, the result is unpredictable. You can fix this by using the cin.get routine instead, with a fixed amount of characters read.

-Antti Keskinen

----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
GeneralRe: while loop problem Pin
CarteBlanche27-Jan-04 7:56
CarteBlanche27-Jan-04 7:56 
GeneralCount the number of characters in a CString Pin
mr200327-Jan-04 7:13
mr200327-Jan-04 7:13 
GeneralRe: Count the number of characters in a CString Pin
monrobot1327-Jan-04 7:23
monrobot1327-Jan-04 7:23 
GeneralRe: Count the number of characters in a CString Pin
Mukkie27-Jan-04 7:36
Mukkie27-Jan-04 7:36 
GeneralRe: Count the number of characters in a CString Pin
toxcct27-Jan-04 8:51
toxcct27-Jan-04 8:51 
GeneralRe: Count the number of characters in a CString Pin
mr200327-Jan-04 9:18
mr200327-Jan-04 9:18 
GeneralRe: Count the number of characters in a CString Pin
toxcct27-Jan-04 20:27
toxcct27-Jan-04 20:27 
GeneralRe: Count the number of characters in a CString Pin
Mukkie27-Jan-04 10:19
Mukkie27-Jan-04 10:19 
GeneralWord API - Insert page break after every hyperlink problem Pin
leemidgley27-Jan-04 7:05
leemidgley27-Jan-04 7:05 
Questiona CArray of structures containing other CArrays? Pin
b_girl27-Jan-04 6:26
b_girl27-Jan-04 6:26 
AnswerRe: a CArray of structures containing other CArrays? Pin
Diddy27-Jan-04 6:34
Diddy27-Jan-04 6:34 
GeneralRe: a CArray of structures containing other CArrays? Pin
b_girl27-Jan-04 6:49
b_girl27-Jan-04 6:49 
GeneralRe: a CArray of structures containing other CArrays? Pin
b_girl27-Jan-04 7:31
b_girl27-Jan-04 7:31 
GeneralRe: a CArray of structures containing other CArrays? Pin
Antti Keskinen27-Jan-04 7:57
Antti Keskinen27-Jan-04 7:57 
GeneralRe: a CArray of structures containing other CArrays? Pin
b_girl27-Jan-04 8:04
b_girl27-Jan-04 8:04 
GeneralRe: a CArray of structures containing other CArrays? Pin
Antti Keskinen27-Jan-04 9:35
Antti Keskinen27-Jan-04 9:35 
GeneralRe: a CArray of structures containing other CArrays? Pin
Diddy27-Jan-04 10:47
Diddy27-Jan-04 10:47 

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.