c++ - Adding a string to a string pointer -


is possible add string string pointer in c++? not working example:

string* temp; temp[0] = "string"; 

just it's possible in:

string temp[3]; temp[0] = "string"; 

before suggesting use normal array or copy different fixed array, string pointer needs returned in function. eg.

string* someclass::toarray(string str) 

i open other suggestions how can return array function.

independing of string code snippet

string* temp; temp[0] = "string"; 

if compiled results in undefined behaviour because pointer temp either has indeterminate value (if local variable) or null , may not derefence it.

provided code snippet

string temp[3]; temp[0] = "string"; 

is valid write example

string* other_temp = temp; other_temp[0] = "string"; 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -