[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] c++ og strings



On Monday 07 July 2003 22:32, you wrote:
> hej venner
>
> jeg er ved at blive lidt irriteret, så jeg håber I kan hjælpe mig. 
<snip>
> ...
> void XML_template::VersionText()
> {
>         string output("something");
>
>         output  = "XML_template class v. " + CurrentVersion + "\n";
>         output += "Build date is " + __DATE__;
>
>         cout << output;
>
> }
> ...
>
> Og jeg får så
> ...
> In file included from morlog.all_cpp.cpp:3:
> xmltemplate.cpp: In method `void XML_template::VersionText()':
> xmltemplate.cpp:51: invalid operands `const char[23]' and `char *' to
> binary `operator +'
> xmltemplate.cpp:52: invalid operands `const char[15]' and `const
> char[12]'
> to binary `operator +'
> ...
>
> Det lader til at den har glemt at overloade +-operatoren.
> Der er noget galt, det var derfor at jeg lavede test programmet, for at
> vide om det bare var mig der havde en begynder fejl med strings, men det
> lod det ikke til at være.
>
> Har I nogen forslag til hvad der er galt?

Det er fordi du prøver at addere to udtryk med typerne const char[15] og const 
char[12], ( for "Build date is " + __DATE__;) og der findes ingen + operator 
til addering af de to typer. Løsningen kan f.eks. være at skrive:

output  = std::string("XML_template class v. ") + CurrentVersion + "\n";
output += std::string("Build date is ") + __DATE__;

Hilsen
Jonas


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *