Error: cannot add two pointers

It gives an error in the header about this piece of code:

string DDateTime::date2OracleDate(DATE Date)
{
    string s;
    s="TO_DATE('" + DateFormat("%d/%m/%Y",Date) + "','dd/MM/YYYY')";
    return s;
}

I do not understand how this is possible, no pointers.

EDIT:

string DDateTime::DateFormat(string sFormat,DATE Date)
{
    struct tm tmTemp;
    RipOf_AfxTmFromOleDate(Date, tmTemp);
    RipOf_AfxTmConvertToStandardFormat(tmTemp);
    char sFormatted[MAX_TIME_BUFFER_SIZE];
    strftime(sFormatted, MAX_TIME_BUFFER_SIZE, sFormat.c_str(), &tmTemp);
    return sFormatted;
}
+3
source share
5 answers

The following should work better:

string DDateTime::date2OracleDate(DATE Date)
{
    string s = "TO_DATE('";
    s += DateFormat("%d/%m/%Y",Date);
    s += "','dd/MM/YYYY')";
    return s;
}
+5
source

The three lines you are trying to add are C-style lines; each of them is a pointer to the contents of the string. At least I assume that it DataFormatreturns a C style string; This is not a standard feature, so I don’t know what it does.

++ "" , ++, , char* . std::string, "" C- .

string s = "TO_DATE(";
s += DateFormat(whatever);
s += "','dd/MM/YYYY')";

string s = string("TO_DATE(") + DateFormat(whatever) + "','dd/MM/YYYY')";
+3

char*. , string, string .

s=string("TO_DATE('") + DateFormat("%d/%m/%Y",Date) + string("','dd/MM/YYYY')"); 
+2

DateFormat, char * - std:: string, , - .

. :

std::string a, b;
b = "foo";
a = "literal" + b + "literal";

:

std::string a, b;
b = "foo";
a = "literal" + b.c_str() + "literal";

, DateFormat std::string.

s="TO_DATE('" + std::string(DateFormat("%d/%m/%Y",Date)) + "','dd/MM/YYYY')";

.

1

, DateFormat , + std::string + literal. .

2

, Amardeep , DateFormat char *, , ( catch). , , -Wall -Wextra gcc, , defyend char *.

, - . ( std::string, char * ).

, - DateFormat sFormatted std::string.

    return std::string(sFormatted);
+2
source
s="TO_DATE('" + DateFormat("%d/%m/%Y",Date) + "','dd/MM/YYYY')";

means (for the compiler) that you are adding a pointer const char*to something else (maybe char*?) returned / converted from DateFormat, and then add another pointer to it const char*.

Try this to get your compiler to find the correct overloads stringfor operator+:

s=string("TO_DATE('") + DateFormat("%d/%m/%Y",Date) + "','dd/MM/YYYY')";
+1
source

Source: https://habr.com/ru/post/1751539/


All Articles