我正在尝试在头文件函数中将String转换为大写。但是,当我尝试执行此操作时,出现错误消息“无法从'class String'转换为'char'。
这是我的代码-
#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;
}
这只是头文件中代码的功能部分。 “ PatientState”在构造函数中定义为字符串。让我知道是否需要发布更多代码。请以任何方式提供帮助。
谢谢-乔希
最佳答案
C ++中没有String这样的类型。如果您的意思是C ++ / CLI,那么我认为返回类型应声明为String ^。
如果这只是一个拼写错误,而您的意思是class std :: string,那么编写起来会更简单
for ( char c : patientState ) putchar (toupper(c));
关于c++ - 将字符串值更改为C++头文件中的大写?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20182366/