Je voudrais convertir stringen chartableau mais pas char*. Je sais comment convertir une chaîne en char*(en utilisant mallocou de la manière dont je l'ai publiée dans mon code) - mais ce n'est pas ce que je veux. Je veux simplement convertir stringen char[size]tableau. C'est possible?
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
int main()
{
// char to string
char tab[4];
tab[0] = 'c';
tab[1] = 'a';
tab[2] = 't';
tab[3] = '\0';
string tmp(tab);
cout << tmp << "\n";
// string to char* - but thats not what I want
char *c = const_cast<char*>(tmp.c_str());
cout << c << "\n";
//string to char
char tab2[1024];
// ?
return 0;
}