On my computer (Win10, WSL 1, Ubuntu 20.04)
This code would compile and run correctly,
#include <iostream>
#include <cstring>
#include <sstream>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
char *test[30];
string a;
cin >> a;
// stringstream ss;
strcpy(test[0], a.c_str());
cout << test[0] << endl;
}
Input: "abc"
Output: "abc"
But this code would encounter a segmentation default:
#include <iostream>
#include <cstring>
#include <sstream>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
char *test[30];
string a;
cin >> a;
stringstream ss;
strcpy(test[0], a.c_str());
cout << test[0] << endl;
}
Input: "abc"
Output: Segmentation fault (core dumped)