LPCSTR data type conversion in problem in c++

71 Views Asked by At

I got some JSON value from swagger. I need to convert those values in my function accepted formate.

mt4 function:

JournalRequest(const int mode,const __time32_t from,const __time32_t to,LPCSTR filter,int *total)

for converting date I just typecast (__time32_t) and it all works. But when I try to convert filter value from string to LPCSTR it only returns the first character value. I got stuck. any help, please?

I am new to StackOverflow so forgive me if the question is not cleared.

Here is my code:

            int total;
             ServerLog* records;
             web::json::value jTrades;
             utility::string_t from, to, filter, mode;

             std::wistringstream ss;
             web::json::value jRecords;
             time_t _from = 0, _to = 0;
             int _mode;
             int k = 0;
             int year = 0, month = 0, day = 0, hour = 0, min = 0;

             mode = params[U("mode")];
             to = params[U("to")];
             from = params[U("from")];
             filter = params[U("filter")];

            std::string fromStringT(filter.begin(), filter.end());
        

         loginfo << "Input From: " << _from << " To:" << _to << " Filter:"  << filter << endl;

         records = man->JournalRequest(_mode, (__time32_t)_from, (__time32_t)_to, filter, &total);
1

There are 1 best solutions below

2
Aykhan Hagverdili On

This should do:

std::string s{ filter };

It will copy the string. If you simply want a better wrapper around the pointer, and not to copy the buffer, you may do:

std::string_view s{ filter };