I hope I have clearly stated my goal in the topic and following is the code I am using.
#include <stdio.h>
#include <inttypes.h>
#include <iostream>
using namespace std;
int main() {
const char *data_ptr =(char*)"test";
const uint8_t* p = reinterpret_cast<const uint8_t*>(&data_ptr);
uint8_t* p1= const_cast<uint8_t*>(p);
char* p2 = reinterpret_cast<char*>(p1);
const char *final= const_cast<const char*>(p2);
string s1( data_ptr);
string s( reinterpret_cast<char const*>(p1),4) ;
cout<<"data_ptr is "<<data_ptr<<endl;
cout<<"p "<<p<<endl;
cout<<"p1 "<<p1<<endl;
cout<<"p2 "<<p2<<endl;
cout<<"final is "<<final<<endl;
cout<<"final1 is "<<s1.size() << "<-->"<<s.size()<<endl;
return 0;
}
and what it prints is as follows.
data_ptr is test
p X@
p1 X@
p2 X@
final is X@
final1 is 4<-->4
What should I do to get the "test" as a string.