Problems with txChart Arduino - c++

I'm having issues with this two lines:
const unsigned char* sendstring = reinterpret_cast<const unsigned char *>( "Hello" );
txChar.writeValue(sendstring);
is giving me this error:
invalid conversion from 'const unsigned char*' to 'unsigned char' [-fpermissive]
I was trying to convert the sendstring variable in the first line but no.

Related

How to fix: cannot convert 'uint8_t (*)[50] {aka unsigned char (*)[50]}' to 'uint8_t* {aka unsigned char*}'

Im programming ATMEGA328p for a specific problema. Im using libraries in C and C++.
When I compile the code the present erro apears:
error: cannot convert 'uint8_t ()[50] {aka unsigned char ()[50]}' to 'uint8_t* {aka unsigned char*}' for argument '2' to 'void SendXbee(char, uint8_t*)
My call to function is:
uint8_t tempBuffer[50]
SendXbee(_data, &tempBuffer);
In library headfile:
void SendXbee(char Data, uint8_t *Frame);
In .c archive the function is:
void SendXbee(char Data, uint8_t* Frame){
.
.
.
xBeeAPI_To_Buffer_From_Frame(&Frame, &transmitFrame);
}
What im doing wrong?

error: invalid conversion from 'void*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]

I am trying to import a C library into my C++ project but I'm stuck with this error
invalid conversion from 'void*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]
uint8_t const* raw = static_cast(getPointerToData(id, message->data, message->length));
^
compilation terminated due to -Wfatal-errors.
This code compile well using C compiler but get this error using C++ one
bool XbusMessage_getDataItem(void* item, enum XsDataIdentifier id, struct XbusMessage const* message)
{
uint8_t const* raw = (getPointerToData(id, message->data, message->length));
Can you help me?
Thanks
You need to explicitly cast the return value from getPointerToData to const uint8_t*. Implicit conversions between pointer types are not allowed in C++ but are in C.
Try:
uint8_t const* raw = static_cast<uint8_t const*>(getPointerToData(id, message->data, message->length));
Edit:
You can also use a C-style cast if you want to keep the C code C and not C++.
uint8_t const* raw = (uint8_t const*)(getPointerToData(id, message->data, message->length));
This code posted by Jean-François Fabre works
uint8_t const* raw = (getPointerToData(id, static_cast<const uint8_t*>(message->data), message->length));
Thanks!

error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]

I get the following error:
2 smartcard.c: In member function ‘virtual bool cSmartCards::ParseLine(const char*, bool)’:
3 smartcard.c:1187:25: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
4 char *r=index(line,':');
5 ^
The code is:
1184
1185 bool cSmartCards::ParseLine(const char *line, bool fromCache)
1186 {
1187 char *r=index(line,':');
1188 if(!r) return false;
I included "string.h"
How can I rewrite line 1187?
index() can be found in string.h.
Either or both of the following:
index returns const char*, not a char*. So, make r a const char*, not a char*.
The function index is written to expect a char*, not a const char*. I cannot safely suggest a fix for this without knowing what index is and does.
The answer is the following:
Function index is found in string.h.
Change line 1187 to: const char *r=index(line,':');

invalid conversion from 'const char*' to 'std::basic_ostream<char>::char_type {aka char}'

Can't get around this problem
ofstream out;
out.open("o");
string a[5][5];
//fill array with letters from 'in.get(ch)'...and then i've tryed:
//1
out.put(a[row[0]][col[1]].c_str()); //=>invalid conversion from 'const char*' to 'std::basic_ostream<char>::char_type {aka char}'
//2:
out.put(const_cast<char *>(a[row[0]][col[1]].c_str())); //=>invalid conversion from 'char*' to 'std::basic_ostream<char>::char_type {aka char}'
//3
char x=const_cast<char *>(a[row[0]][col[1]].c_str());
out.put(x); //=>invalid conversion from 'char*' to 'char'
Nothin seems to be working. Can you help me? What should i do?
ofstream::put() is for putting individual characters, not strings, to the stream.
If you want to print the string to the file stream, why not simply use <<:
out << a[row[0]][col[1]];

C++ boost error: cannot convert const value type* (aka const wchar_t*) to const char* in initialization

I'm trying to search for a word from a file using the boost module and c++ and I'm stuck on this error message:
error: cannot convert 'const value_type* {aka const wchar_t*}' to 'const char*' in initialization
The error comes from this line of code:
const char* file_path = itr->path ().filename ().c_str();
Thanks.
It is telling you you need this:
const wchar_t* file_path = itr->path ().filename ().c_str();