Click here to Skip to main content
15,885,278 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: What`s a palette in the parsing a bitmap context Pin
phil.o10-Mar-20 21:46
professionalphil.o10-Mar-20 21:46 
GeneralRe: What`s a palette in the parsing a bitmap context Pin
Calin Negru11-Mar-20 7:32
Calin Negru11-Mar-20 7:32 
GeneralRe: What`s a palette in the parsing a bitmap context Pin
leon de boer12-Mar-20 5:15
leon de boer12-Mar-20 5:15 
QuestionHaving issues with the cin.getline() function in C++ Pin
Member 147670008-Mar-20 14:29
Member 147670008-Mar-20 14:29 
AnswerRe: Having issues with the cin.getline() function in C++ Pin
k50548-Mar-20 15:37
mvek50548-Mar-20 15:37 
GeneralRe: Having issues with the cin.getline() function in C++ Pin
Member 147670009-Mar-20 10:55
Member 147670009-Mar-20 10:55 
GeneralRe: Having issues with the cin.getline() function in C++ Pin
Member 147670009-Mar-20 11:01
Member 147670009-Mar-20 11:01 
GeneralRe: Having issues with the cin.getline() function in C++ Pin
k50549-Mar-20 12:12
mvek50549-Mar-20 12:12 
Sure, but if you do this
C++
if(weight != "\n")
{
  // ... 
  pigs[i].SetPigWeight(pigWeight);
}
else
    pigs[i].SetPigWeight(100.0); // Set default weight to 100.0
// ... 
Now, when you hit enter, you would expect that the default weight would be used (i.e. set to 100.0), if the comparison is working as you expect. But it won't be, it will be set to zero. Believe me when I tell you that
C++
if (weight != "\n")
does not compare objects of type char* (ie c-style strings). You must use strcmp() to compare c-style strings. Better than using iostream::getline, take a look at std::getline. Your code might then look something like
C++
#include <string>
// ...
string input_string;
// ...
getline(cin, input_string);
if(input_string.length() != 0) // User entered a value
{
    // ...
}

Furthermore, what happens if you enter one hundred for the weight? It doesn't get set to 100, but zero, since atof("one hundred") == 0.0. A good solution should check that the input is a number. At the very least that the input string contains only the characters "0123456789.". Ideally you would check that there was only one decimal point, too.
GeneralRe: Having issues with the cin.getline() function in C++ Pin
Member 1476700010-Mar-20 8:49
Member 1476700010-Mar-20 8:49 
GeneralRe: Having issues with the cin.getline() function in C++ Pin
k505410-Mar-20 9:04
mvek505410-Mar-20 9:04 
AnswerRe: Having issues with the cin.getline() function in C++ Pin
Stefan_Lang8-Mar-20 22:26
Stefan_Lang8-Mar-20 22:26 
GeneralRe: Having issues with the cin.getline() function in C++ Pin
k50549-Mar-20 12:29
mvek50549-Mar-20 12:29 
GeneralRe: Having issues with the cin.getline() function in C++ Pin
Stefan_Lang9-Mar-20 21:41
Stefan_Lang9-Mar-20 21:41 
Generala not fun question: how to deploy a utility program written in MFC and C++ Pin
Southmountain8-Mar-20 12:56
Southmountain8-Mar-20 12:56 
GeneralRe: a not fun question: how to deploy a utility program written in MFC and C++ Pin
Jon McKee8-Mar-20 13:01
professionalJon McKee8-Mar-20 13:01 
GeneralRe: a not fun question: how to deploy a utility program written in MFC and C++ Pin
Southmountain8-Mar-20 16:06
Southmountain8-Mar-20 16:06 
GeneralRe: a not fun question: how to deploy a utility program written in MFC and C++ Pin
Maximilien8-Mar-20 15:38
Maximilien8-Mar-20 15:38 
GeneralRe: a not fun question: how to deploy a utility program written in MFC and C++ Pin
Southmountain8-Mar-20 16:03
Southmountain8-Mar-20 16:03 
GeneralRe: a not fun question: how to deploy a utility program written in MFC and C++ Pin
Shao Voon Wong8-Mar-20 15:51
mvaShao Voon Wong8-Mar-20 15:51 
GeneralRe: a not fun question: how to deploy a utility program written in MFC and C++ Pin
Southmountain8-Mar-20 16:04
Southmountain8-Mar-20 16:04 
GeneralRe: a not fun question: how to deploy a utility program written in MFC and C++ Pin
Shao Voon Wong8-Mar-20 16:09
mvaShao Voon Wong8-Mar-20 16:09 
GeneralRe: a not fun question: how to deploy a utility program written in MFC and C++ Pin
Southmountain8-Mar-20 16:24
Southmountain8-Mar-20 16:24 
GeneralRe: a not fun question: how to deploy a utility program written in MFC and C++ Pin
Shao Voon Wong8-Mar-20 16:28
mvaShao Voon Wong8-Mar-20 16:28 
GeneralRe: a not fun question: how to deploy a utility program written in MFC and C++ Pin
Southmountain8-Mar-20 16:08
Southmountain8-Mar-20 16:08 
QuestionTrying to add a menu bar to a dialog Pin
ForNow29-Feb-20 16:07
ForNow29-Feb-20 16:07 

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.