编译期间MSVC中的字符串长度限制?

时间:2015-07-16 17:34:43

标签: c++ gcc string-length

我正在将C ++代码从Linux转换为Windows(使用Visual Studio 2013)。但是MSVC对字符串有长度限制(大约2048字节?),而GCC则没有。我的问题是,有一个包含几个巨大字符串的配置文件,它在GCC下运行良好。但MSVC报告编译错误为

  

错误C2026:字符串太大,尾随字符被截断。

字符串很简单,<HL7Message DomainID="1" DomainName="Domain" OrganizationID="example$organizationid" OrganizationName="example$organiationname" SourceSystem="DR"> <MSH parentseq="-1" seq="1"> <Segment component="-1" field="0" subcomponent="-1">MSH</Segment> <FieldSeparator component="-1" field="1" subcomponent="-1">|</FieldSeparator> <EncodingCharacters component="-1" field="2" subcomponent="-1">^~\&amp;</EncodingCharacters> <SendingFacility component="-1" field="4" subcomponent="-1"> <NamespaceID component="1" field="4" subcomponent="-1">RP-1</NamespaceID> </SendingFacility> <DateTime component="-1" field="7" subcomponent="-1"> <Time component="1" field="7" subcomponent="-1">systemdatetime</Time> </DateTime> <MessageType component="-1" field="9" subcomponent="-1"> <MessageCode component="1" field="9" subcomponent="-1">ADT</MessageCode> <TriggerEvent component="2" field="9" subcomponent="-1">A28</TriggerEvent> </MessageType> </MSH> <PID parentseq="-1" seq="2"> <Segment component="-1" field="0" subcomponent="-1">PID</Segment> <SetID-PID component="-1" field="1" subcomponent="-1">1</SetID-PID> <PatientIdentifierList component="-1" field="3" subcomponent="-1"> <IDNumber component="1" field="3" subcomponent="-1">example$patientid</IDNumber> </PatientIdentifierList> <PatientName component="-1" field="5" subcomponent="-1"> <FamilyName component="1" field="5" subcomponent="-1"> <Surname component="1" field="5" subcomponent="1">example$firstname</Surname> </FamilyName> <GivenName component="2" field="5" subcomponent="-1">data$lastname</GivenName> <SecondAndFurtherGivenNames component="3" field="5" subcomponent="-1">example$middle</SecondAndFurtherGivenNames> </PatientName> <DateTimeOfBirth component="-1" field="7" subcomponent="-1"> <Time component="1" field="7" subcomponent="-1">example$dob</Time> </DateTimeOfBirth> </PID> <PV1 parentseq="-1" seq="3"> <Segment component="-1" field="0" subcomponent="-1">PV1</Segment> <SetID-PV1 component="-1" field="1" subcomponent="-1">1</SetID-PV1> <PatientClass component="-1" field="2" subcomponent="-1">O</PatientClass> <AssignedPatientLocation component="-1" field="3" subcomponent="-1"> <PointOfCare component="1" field="3" subcomponent="-1">example$organizationname</PointOfCare> </AssignedPatientLocation> <AttendingDoctor component="-1" field="7" subcomponent="-1"> <IDNumber component="1" field="7" subcomponent="-1">example$providerid</IDNumber> <FamilyName component="2" field="7" subcomponent="-1"> <Surname component="2" field="7" subcomponent="1">example$providerlast</Surname> </FamilyName> <GivenName component="3" field="7" subcomponent="-1">example$providerfirst</GivenName> </AttendingDoctor> <ReferringDoctor component="-1" field="8" subcomponent="-1"> </ReferringDoctor> </PV1> <OBX parentseq="3" seq="4"> <Segment component="-1" field="0" parentseq="-1" subcomponent="-1">OBX</Segment>> <ObservationIdentifier component="-1" field="3" parentseq="-1" subcomponent="-1"> <Identifier component="1" field="3" parentseq="-1" subcomponent="-1">example$observationcode</Identifier> <Text component="2" field="3" parentseq="-1" subcomponent="-1">example$text</Text> <NameofCodingSystem component="3" field="3" parentseq="-1" subcomponent="-1">example$observationcodesystem</NameofCodingSystem> </ObservationIdentifier> <ObservationValue component="-1" field="5" parentseq="-1" subcomponent="-1"> <Identifier component="1" field="5" parentseq="-1" subcomponent="-1">example$numericvalue1</Identifier> </ObservationValue> <Units component="-1" field="6" parentseq="-1" subcomponent="-1"> <Identifier component="1" field="6" parentseq="-1" subcomponent="-1">example$numericunitcd</Identifier> </Units> <ObservationResultStatus component="-1" field="11" parentseq="-1" subcomponent="-1">F</ObservationResultStatus> <DateTimeOfObservation component="-1" field="14" parentseq="-1" subcomponent="-1"> <Time component="1" field="14" parentseq="-1" subcomponent="-1">example$dateofobservation</Time> </DateTimeOfObservation> </OBX> <ZPI parentseq="-1" seq="8"> <Segment component="-1" field="0" subcomponent="-1">ZPI</Segment> <RecordType component="-1" field="1" subcomponent="-1"> <Text component="2" field="1" subcomponent="-1">Risk Score</Text> </RecordType> </ZPI> </HL7Message> 很大。

CONFIGSTRING

针对此问题的任何解决方案?我可以使用Windows下的GCC将配置文件单独编译为目标文件并将其链接到其他文件吗?如果可能,任何人都可以简要地告诉我该怎么做?

1 个答案:

答案 0 :(得分:1)

根据MSDN文档,这应该有效:

const std::string str =
  "xxxx" // Max 2048 bytes
  "xxxx" // Max 2048 bytes
         // ... and so on (up to 65535 bytes)
  ;

如果仍然不够,请执行:

std::string str;
str = "part1";
str += "part2";
str += "part3"; // And so on.
  

我可以使用Windows下的GCC将配置文件单独编译为目标文件并将其链接到其他文件吗?

不,他们使用不同的C ++标准库。