Click here to Skip to main content
15,912,665 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: c libraries needed to deal with bitmaps Pin
Richard MacCutchan14-Mar-20 7:13
mveRichard MacCutchan14-Mar-20 7:13 
GeneralRe: c libraries needed to deal with bitmaps Pin
Calin Negru14-Mar-20 8:18
Calin Negru14-Mar-20 8:18 
GeneralRe: c libraries needed to deal with bitmaps Pin
phil.o14-Mar-20 8:37
professionalphil.o14-Mar-20 8:37 
GeneralRe: c libraries needed to deal with bitmaps Pin
Richard MacCutchan14-Mar-20 9:27
mveRichard MacCutchan14-Mar-20 9:27 
GeneralRe: c libraries needed to deal with bitmaps Pin
phil.o14-Mar-20 9:34
professionalphil.o14-Mar-20 9:34 
GeneralRe: c libraries needed to deal with bitmaps Pin
Richard MacCutchan14-Mar-20 21:58
mveRichard MacCutchan14-Mar-20 21:58 
GeneralRe: c libraries needed to deal with bitmaps Pin
Calin Negru12-Mar-20 0:35
Calin Negru12-Mar-20 0:35 
GeneralRe: c libraries needed to deal with bitmaps Pin
Victor Nijegorodov11-Mar-20 22:45
Victor Nijegorodov11-Mar-20 22:45 
GeneralRe: c libraries needed to deal with bitmaps Pin
Calin Negru12-Mar-20 0:43
Calin Negru12-Mar-20 0:43 
AnswerRe: c libraries needed to deal with bitmaps Pin
leon de boer12-Mar-20 5:31
leon de boer12-Mar-20 5:31 
GeneralRe: c libraries needed to deal with bitmaps Pin
Victor Nijegorodov12-Mar-20 8:39
Victor Nijegorodov12-Mar-20 8:39 
GeneralRe: c libraries needed to deal with bitmaps Pin
leon de boer12-Mar-20 13:19
leon de boer12-Mar-20 13:19 
QuestionWhat`s a palette in the parsing a bitmap context Pin
Calin Negru10-Mar-20 5:00
Calin Negru10-Mar-20 5:00 
AnswerRe: What`s a palette in the parsing a bitmap context Pin
phil.o10-Mar-20 5:16
professionalphil.o10-Mar-20 5:16 
GeneralRe: What`s a palette in the parsing a bitmap context Pin
Calin Negru10-Mar-20 6:34
Calin Negru10-Mar-20 6:34 
GeneralRe: What`s a palette in the parsing a bitmap context Pin
phil.o10-Mar-20 7:05
professionalphil.o10-Mar-20 7:05 
GeneralRe: What`s a palette in the parsing a bitmap context Pin
harold aptroot10-Mar-20 16:31
harold aptroot10-Mar-20 16:31 
GeneralRe: What`s a palette in the parsing a bitmap context Pin
phil.o10-Mar-20 19:27
professionalphil.o10-Mar-20 19:27 
GeneralRe: What`s a palette in the parsing a bitmap context Pin
Calin Negru10-Mar-20 21:06
Calin Negru10-Mar-20 21:06 
GeneralRe: What`s a palette in the parsing a bitmap context Pin
phil.o10-Mar-20 21:11
professionalphil.o10-Mar-20 21:11 
GeneralRe: What`s a palette in the parsing a bitmap context Pin
Calin Negru10-Mar-20 21:30
Calin Negru10-Mar-20 21:30 
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 
for a short test in my class, we had to write code about pigs that allowed the user to enter information about a set of pigs (e.g. the pigs' names, breed, weight, gender, etc.). We were to create a class called pigs that would be able to hold the pigs' information. There was nothing wrong with the class itself, the problem I'm having is actually in the main function.
cout << "Enter the pig gender (\'m\'/\'f\')(if not press \'enter\' for none): ";
cin.getline(pigGender, 10);
if(pigGender != "\n")
{
    while(pigGender != "m" && pigGender != "f")
    {
        cout << "Invalid gender, please enter a valid gender m or f(if not press \'Enter\'): ";
        cin.getline(pigGender, 10);
        if(pigGender != "\n")
        {
            //cout << "if branch, pigGender:" << pigGender;
            gender = pigGender[0];
        }
        else
        {
            //cout << "else branch, pigGender:" << pigGender;
            gender = ' ';
            break;
        }
    }
    pigs[i].SetPigGender(gender);
}

The piece of code above, shows how I'm trying to obtain the pig's gender from the user. I made it so that if the user doesn't know the gender, they can just hit enter to move on (as I did with other features that worked fine). The problem is that when you hit enter, the pigGender string doesn't seem to take the newline character. Also, I understand how the getline function works (takes in a newline and stops), hence I believe when you hit enter, the getline will take in the newline and stop, but here it does not seem to take it in at all. I also made it so that if the user enters a wrong letter (not m or f), then they can still hit enter if they do not know. The commented out codes are checks I implemented to see exactly what was in pigGender. When I enter a charcter that is not a newline it will go to the if branch and dislpay my error message, however, when I hit only enter, it still goes through that if branch instead of the else branch. the checks i commented out show me which branch I am in and the charcter in the pigGender string, and when I hit enter for the newline, there seems to be nothing in the pigGender string. What seems even more bizarre, is that the following code is very similar to what I did above (I actually copied and pasted it and made some changes to make the one above) and it works perfectly.
cout << "Enter the pig weight(if not press \'Enter\'): ";
cin.getline(weight, 10);
if(weight != "\n")
{
    float pigWeight = atof(weight);
    while(pigWeight < 0)
    {
        cout << endl;
        cout << "Invalid weight, please enter a valid weight(if not press \'Enter\'): ";
        cin.getline(weight, 10);
        if(weight != "\n")
        {
            pigWeight = atof(weight);
        }
        else
        {
            pigWeight = 0;
        }
    }
    pigs[i].SetPigWeight(pigWeight);
}

Is there something I'm just not seeing here, because I have been looking at this code since yesterday and have tried a bunch of stuff to fix it but can't. Of course, I do know of many other ways to tackle this problem (like comparing string size instead), but I started with this and its really bugging me that it does not work, so I just want to figure it out just so I can know. If you can help me understand, please respond, I really want to figure this thing out, thank you!

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.