在C ++头文件中将String值更改为大写吗? [英] Change String value to uppercase in a C++ header file?
问题描述
我正在尝试在我的头文件函数中将String转换为大写.但是,当我尝试执行此操作时,出现错误消息无法从'class String'转换为'char'.
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'.
这是我的代码-
#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"在构造函数中定义为字符串.让我知道是否需要发布更多代码.请以任何方式提供帮助.
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.
谢谢-乔什
推荐答案
在C ++中,没有像String这样的类型.如果您的意思是C ++/CLI,那么我认为返回类型应声明为String ^. 如果只是拼写错误,而您的意思是class std :: string,那么编写起来会更简单
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));
这篇关于在C ++头文件中将String值更改为大写吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!