Home > OS >  Using the built-in C function to make parameter variable "seat" upper case
Using the built-in C function to make parameter variable "seat" upper case

Time:11-13

Am trying to make the parameter variable "seat" upper case but I keep getting errors I don't want to include bits/stdc .h header file but am stuck trying to figure it out. I need guidance on how to make it work

Error states 'transform': identifier not found these are the includes i have in the code

#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <iomanip>
#include <cctype>
bool releaseSeat(string seat)
{


    bool releaseSeatOK = false;

    transform(seat.begin(), seat.end(), seat.begin(), ::toupper);

    string passengerName = showOccupant(seat);

    if (passengerName.compare("seat_01A") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }
    else if (passengerName.compare("seat_01B") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }
    else if (passengerName.compare("seat_01C") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }
    else if (passengerName.compare("seat_01D") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }
    else if (passengerName.compare("seat_02A") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }
    else if (passengerName.compare("seat_02B") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }
    else if (passengerName.compare("seat_02C") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }
    else if (passengerName.compare("seat_02D") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }
    else if (passengerName.compare("seat_03A") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }
    else if (passengerName.compare("seat_03B") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }
    else if (passengerName.compare("seat_03C") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }
    else if (passengerName.compare("seat_03D") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }

    else if (passengerName.compare("seat_04A") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }
    else if (seat.compare("04B") == 0)
    {
        passengerName = "seat_04B";
    }
    else if (passengerName.compare("seat_04B") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }
    else if (passengerName.compare("seat_04C") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }
    else if (passengerName.compare("seat_04D") == 0)
    {
        passengerName = "empty";
        releaseSeatOK = true;
    }

    return releaseSeatOK;
}

I've tried what I know based on my knowledge so far since am just starting c This is part of 1000 lines of code I can't include every line, am just getting errors on this line

CodePudding user response:

Did you include <algorithm>? std::transform is found in <algorithm> so if you didn't include it C doesn't know what std::transform is, hence the error.

Edit: I see you don't have <algorithm> included, so just add #include <algorithm> to the top of your code and the error should disappear.

Edit 2: Just iterate over each character in seat and capitalize them, like so:

for (size_t i = 0; i < seat.length(); i  )
{
    seat[i] = toupper(seat[i]);
}

std::transform is not necessary in this case.

  •  Tags:  
  • c
  • Related