Basically, I am trying to do this:
char x[] = "hello"; char* y = new char[sizeof(x)](x); // won't work.
demo
Is there any way to do this cleanly? There are no comments about DO NOT use raw arrays or raw pointers.
Just write a function.
template<typename T, size_t N> T* new_array(T const(&arr)[N]) { T* p = new T[N]; std::copy(std::begin(arr), std::end(arr), p); return p; } int main() { char x[] = "hello"; char* y = new_array(x); }
Path C:
char* y = strdup(x); free(y);
Source: https://habr.com/ru/post/1210185/More articles:https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1210180/how-to-fix-an-encoding-migrating-python-subprocess-to-unicodeliterals&usg=ALkJrhgZNVkjAU8Lv9o2mfGM6_bePYTxLwHow to disable color and remove time - gitPython socket works on local network, but not over Wi-Fi - pythonAngularJS 1.2.28 or 1.3.8? - angularjsHow to create an Android application that can run on API 19 (4.4 Kitkat), but still looks like API 21 (5.0 Lollipop)? - androidHow to initialize a dynamic array of characters with a string literal in C ++? - c ++UICollectionView shows footer for last section only - swiftIIFE calls evaluation function - javascripthttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1210189/refresh-tokens-in-oauth2-should-not-be-replaced-when-getting-a-new-access-token&usg=ALkJrhjY1KX0NgDTLy0DbIBmi1lJGSdpAQAlternative to colon in time format - filenamesAll Articles