Search code examples
c++stringcharheader-filesuppercase

Change String value to uppercase in a C++ header file?


I'm trying to convert a String to uppercase in my header file function. However, when I try to do this I get an error saying "Cannot convert from 'class String' to 'char'.

Here's my code -

#ifndef PATIENT_DEMO_CLASS
#define PATIENT_DEMO_CLASS

// system defined preprocessor statement for cin/cout operations
#include <iostream.h>
// header file from book
#include "tstring.h"
#include <algorithm>
#include <string>

class PatientDemographicInformation
{
    private:
    // patient's state
    String patientState;

    public:
    // constructor
    PatientDemographicInformation(String state);

    // returns the patient's state in all capital letters
    String getPatientState( );
};
// assign values to constructor
PatientDemographicInformation::PatientDemographicInformation(String state)
{
    patientState = state;
}

String PatientDemographicInformation::getPatientState( )
{
    int i=0;
// ------The line below this is where my error occurs--------
    char str[] = {patientState};
    char c;
    while (str[i])
    {
    c=str[i];
    putchar (toupper(c));
    i++;
    }
    return patientState;
}

This is just the function section of code from the header file. 'patientState' is defined in the constructor as a String. Let me know if I need to post more code. Please help in anyway you can.

Thanks - Josh


Solution

  • There is no such type as String in C++. If you mean C++/CLI then I think the return type should be declared as String ^. If it is simply a typo and you mean class std::string then it would be simpler to write

    for ( char c : patientState ) putchar (toupper(c));