I can not get my string data back using pointer to the char array. Could you give me an explanation what i am doing wrong please.
#include "stdafx.h"
#include <conio.h>
#include <string>
using namespace std;
string GetString()
{
return string("255");
}
int _tmain(int argc, _TCHAR* argv[])
{
char* str_p = const_cast<char*>(GetString().c_str());
printf("Pointer : %s\n", str_p);
string str;
str = str_p[0];
str += str_p[1];
str += str_p[2];
printf("Constructed : %s\n", str.c_str());
_getch();
return 0;
}
The console output is :
Pointer :
Constructed :